meters to feet and inches conversion
|
|
Reno Katscher
Registered User
Join date: 2 Jun 2007
Posts: 18
|
06-08-2007 19:05
I have this code to tell how tall an avatar is: default { touch_start(integer num_detected) { vector size; size = llGetAgentSize(llDetectedKey(0)); size = size * 39; size = size /12; llSay(0, "You are " + (string)size.z + " feet tall."  ; //Rotate the texture - all sides of the prim llSetTextureAnim(ANIM_ON | SMOOTH | LOOP | ROTATE, ALL_SIDES, 8, 1, 0, 7, .1); } } It currently returns a string like You are 5.8884527 feet tall. I want it to say you are 5 feet 3 inches tall... Can someone help me with the math I need to do this? Thanks Kim
|
|
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
|
06-08-2007 19:31
You could take the decimal part (perhaps by subtracting the integer portion of the number) and multiply it by 12. That would give you the inches. Then convert that to an integer again.
|
|
Jim Guyot
Tinkerer
Join date: 21 Apr 2007
Posts: 38
|
06-08-2007 20:56
I would change this: size = llGetAgentSize(llDetectedKey(0)); size = size * 39; size = size /12; llSay(0, "You are " + (string)size.z + " feet tall."  ; to the following: sizeCM = llGetAgentSize( llDetectedKey( 0 ) ) / 100; sizeIn = sizeCM.z / 2.54; sizeFt = (integer) (sizeIn / 12); sizeIn = sizeIn - sizeFt; llSay( 0, "You are " + (string) sizeFt + " feet, " + (string) sizeIn + " inches tall." );
|
|
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
|
Metric morbidity
06-08-2007 22:20
This brings up one of my personal hobbyhorses, namely the imminent death of the metric system. It seems to me that with the advent of calculators and computers, the metric system will be returned to the dustbin of history from whence it came. Beyond complex computation, the advantages of the Imperial English system are so manifest that it won't be long before this Napoleonic flash-in-the-pan simply dies out from lack of popular mind-share.
Considering that SL is presumably aimed at a futurist clientelle, it's use of the metric system seems at best ill considered.
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
06-08-2007 22:53
Base 12 vs Base 10... since I grew up learning base 10, and heaven forbid we should have it so easy with 1cm^3 = 1 mL
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
06-09-2007 00:46
vector Size = llGetAgentSize( llDetectedKey(0) ) / 0.3048; integer Feet = Size.z; integer Inches = llRound( Size.z * 12 ) % 12;
Results rounded to nearest inch.
|
|
Reno Katscher
Registered User
Join date: 2 Jun 2007
Posts: 18
|
06-09-2007 09:26
Thanks for all your help! I sort of took a hodge podge of the suggestions and came up with this:
default { touch_start(integer num_detected) {
vector size = llGetAgentSize( llDetectedKey( 0 ) ) / 0.3048; float sizeFT = size.z ; sizeFT =llRound (sizeFT); integer Inches = llRound( size.z * 12 ) % 12;
llSay( 0, "You are " + (string) sizeFT + " feet, "+ (string)Inches +" inches tall." );
The output is You are 6.000000 feet, 9 inches tall.
Actually, I see that rounding the sizeFT is not what I want it to do either. Lets say the value in meters is 1.757527. When I convert that to feet I get 5.741469. I want the output to be 5 feet, 7 inches.
BTW...I am very new to coding..this is the first script I have tried to tweak on my own. I appreciate any and all help! THanks
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
06-09-2007 11:38
Looks pretty close; I think you just want integer sizeFT = (integer)size.z instead of llRound()ing it.
|
|
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
|
06-09-2007 12:07
From: Ralph Doctorow This brings up one of my personal hobbyhorses, namely the imminent death of the metric system. It seems to me that with the advent of calculators and computers, the metric system will be returned to the dustbin of history from whence it came. Beyond complex computation, the advantages of the Imperial English system are so manifest that it won't be long before this Napoleonic flash-in-the-pan simply dies out from lack of popular mind-share.
Considering that SL is presumably aimed at a futurist clientelle, it's use of the metric system seems at best ill considered. Haha, that is really funny, must surely be tongue in cheek. Otherwise one can only presume that you must be US based and it has somehow escaped your notice that rest of the world doesn't reside in the US which is the last bastion of of the anachronistic Imperial system. SL aimed at a global market, very sensibly decided to choose the metric system which is used and understood by the rest of the world.
|
|
Reno Katscher
Registered User
Join date: 2 Jun 2007
Posts: 18
|
06-09-2007 12:56
From: Qie Niangao Looks pretty close; I think you just want integer sizeFT = (integer)size.z instead of llRound()ing it. AH HA! That did it. Thank yo uso much
|