
-----------------------------------
ElimPi
Mon Jun 19, 2006 4:02 pm

Rounding
-----------------------------------
I have a problem with rounding real numbers. I need to be able to round them to two decimal places without using field width specifiers. The reason is that I'm making a shop, and after tax is calculated, I get a real number to an obscenely long number of decimal places. I need to output the number as a Font.Draw, I know how to use realstr, but it puts it to a varying number of decimal places depending on how many digits precede the decimal. Any ideas?

-----------------------------------
[Gandalf]
Mon Jun 19, 2006 5:00 pm


-----------------------------------
Look up the frealstr function.  It looks like this:
frealstr ( r : real, width, fractionWidth : int ) : string
put frealstr (1.657, 0, 1) % round 1.657 to one decimal place (1.7)

-----------------------------------
aldreneo
Mon Jun 19, 2006 8:58 pm


-----------------------------------
Dude I was about to ask how to do rounding, thanks

-----------------------------------
[Gandalf]
Wed Jun 21, 2006 8:36 am


-----------------------------------
No problem.  Maybe it's a sign of Delos' clairvoyance spreading. ;)
Note that this function is only needed when you need to round to a specific amount of decimal places.  If you only need to round a real number to an integer then you can use round (myNum : real) : int.

-----------------------------------
Delos
Wed Jun 21, 2006 9:19 am


-----------------------------------
"]No problem.  Maybe it's a sign of Delos' clairvoyance spreading. ;)

About time too!  What's the point of answering questions if you can't pre-empt other question's answers in the process? :wink:
