Page 1 of 1
Using Decimal Points??? HELP!
Posted: Fri Feb 22, 2008 4:55 pm
by no1g8tor
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
Posted: Fri Feb 22, 2008 7:29 pm
by Janschenkel
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:
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
Hope this helped,
Jan Schenkel.
Posted: Sat Feb 23, 2008 2:04 am
by Mark
Hi Jan,
Shouldn't the following be sufficient...
Code: Select all
set the numberformat to "#.00"
put round(20.999)*1 into fld "Your Field"
or am I missing something?
Best,
Mark
Posted: Mon Feb 25, 2008 3:45 am
by Mark Smith
You might also want to check the 'format' function.
put format("%0.3d", someNumber)
should put xx.xxx into the message box.
Posted: Mon Feb 25, 2008 3:49 am
by Mark
Hi Mark,
I believe OP wants "xx.xxx" to be converted to "xx.00".
Best,
Mark
Posted: Tue Feb 26, 2008 2:46 pm
by no1g8tor
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?
Posted: Tue Feb 26, 2008 2:52 pm
by Mark
No1g8tor,
Please post your repeat loop.
Mark
Posted: Tue Feb 26, 2008 4:22 pm
by no1g8tor
I figured out a way around it.
I should have done this before. I was thinking outside the box when i shold have been inside it...lol.
I just converted the number to the xx.xx format in the original location before I moved it to the list.
Thank you all for your help.
This forum is GREAT.