Does someone know which is the function that let me take only the first two decimals in a float number?
let's say that i have a number 23.4567 but I only want to use 23.45
These forums are CLOSED. Please visit the new forums HERE
how to get only 2 decimals |
|
|
Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
|
03-22-2007 13:06
Does someone know which is the function that let me take only the first two decimals in a float number?
let's say that i have a number 23.4567 but I only want to use 23.45 _____________________
First goes before
AW Devices |
|
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
|
03-22-2007 13:09
Without looking at the wiki. An old trick is to (1) multiply but 100, (2) make it an integer, (3) make it a real number and divide my 100.
23.4567 23.4567 * 100 = 2345.67 integer would make it 2345 2345 /100 = 23.45 |
|
Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
|
03-22-2007 13:13
That's a solutin. Thanks a lot. But is there any built-in function to get it?
_____________________
First goes before
AW Devices |
|
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
|
03-22-2007 13:15
Without looking at the wiki. An old trick is to (1) multiply but 100, (2) make it an integer, (3) make it a real number and divide my 100. 23.4567 23.4567 * 100 = 2345.67 integer would make it 2345 2345 /100 = 23.45 After multiplying by 100, add 0.5, and then llFloor it. That will do accurate "rounding" instead of "truncating". You can see that the rounding in the above example is wrong. And, in the end, if you want to "llSay" it, you'll have to do more than just casting it to a string, because you would otherwise end up with (23.45000000 instead of 23.45). You might have to do something silly like search for the decimal place in the string, and then keep the substring up to 2 position after the decimal. _____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator |
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
03-22-2007 13:36
After multiplying by 100, add 0.5, and then llFloor it. That will do accurate "rounding" instead of "truncating". You can see that the rounding in the above example is wrong. Actually, CODE Also performs rounding. llFloor is the same as "truncating", or casting to an integer. _____________________
|
|
Azul Wilder
Registered User
Join date: 29 Jan 2007
Posts: 87
|
03-22-2007 13:45
For what I need, it is better to truncate it. So the example of Destiny should work.
I must to come to terms with the fact that there is not a built-in function that makes the job, so I will create a global function. But if someone know about a built-in function, please let me know. Thanks a lot. _____________________
First goes before
AW Devices |