Posted: Mon Jun 19, 2006 4:02 pm Post subject: 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?
Sponsor Sponsor
[Gandalf]
Posted: Mon Jun 19, 2006 5:00 pm Post subject: (No subject)
Look up the frealstr function. It looks like this:
frealstr ( r : real, width, fractionWidth : int ) : string
code:
put frealstr (1.657, 0, 1) % round 1.657 to one decimal place (1.7)
aldreneo
Posted: Mon Jun 19, 2006 8:58 pm Post subject: (No subject)
Dude I was about to ask how to do rounding, thanks
[Gandalf]
Posted: Wed Jun 21, 2006 8:36 am Post subject: (No subject)
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
Posted: Wed Jun 21, 2006 9:19 am Post subject: (No subject)
[Gandalf] wrote:
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?