Using Decimal Points??? HELP!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Using Decimal Points??? HELP!
I have a situation that involves times that need to be rounded to the nearest hundreth. xx.xx. I am using the following command...Put round (Speed,2) into rspeed... and it works the only problem is that if it is 20.999, it makes it 21 but I need it to say 21.00 with the .00.
I tried the setnumberformat in the scripts, but it messes with the repeat statements.
Can I set just a field with the format xxx.xx.
Thanks
I tried the setnumberformat in the scripts, but it messes with the repeat statements.
Can I set just a field with the format xxx.xx.
Thanks
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
You have to trick the engine into formatting the decimal number as a string at the right time. The easiest way to do this is by concatenating the number with a string.
Here's some example code:
Hope this helped,
Jan Schenkel.
Here's some example code:
Code: Select all
on mouseUp
set the numberFormat to "#.00"
repeat with i = 1 to 5
put i + random(100) / 100 into tRandom
put round(tRandom) & "" into tRounded --> concatenate here
put tRounded & return after tList
end repeat
answer tList
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Hi Jan,
Shouldn't the following be sufficient...
or am I missing something?
Best,
Mark
Shouldn't the following be sufficient...
Code: Select all
set the numberformat to "#.00"
put round(20.999)*1 into fld "Your Field"
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Contact:
I am sorry if I wasnt clear. Exactly what I want is as follows. I have 8 Numbers in a field hat have longer than 2 decimal points.
31.33333
32.45
45.44433
56.1222223
etc...
I need them to be rounded to the nearest .xx.
They should look like
31.33
32.45
45.44
56.12
i used the following
set the numberFormat to "#.00"
Put round (Speed,2) into rspeed
The only problem with this is that it is in a loop and when it starts back through the loop the second round it changes all the numbers to the x.xx format and then screws up the repeat statement.
could I just convert the numbers after they are placed in curent field?
31.33333
32.45
45.44433
56.1222223
etc...
I need them to be rounded to the nearest .xx.
They should look like
31.33
32.45
45.44
56.12
i used the following
set the numberFormat to "#.00"
Put round (Speed,2) into rspeed
The only problem with this is that it is in a loop and when it starts back through the loop the second round it changes all the numbers to the x.xx format and then screws up the repeat statement.
could I just convert the numbers after they are placed in curent field?