Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Rounding
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ElimPi




PostPosted: 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
Sponsor
sponsor
[Gandalf]




PostPosted: 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




PostPosted: Mon Jun 19, 2006 8:58 pm   Post subject: (No subject)

Dude I was about to ask how to do rounding, thanks
[Gandalf]




PostPosted: Wed Jun 21, 2006 8:36 am   Post subject: (No subject)

No problem. Maybe it's a sign of Delos' clairvoyance spreading. Wink
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




PostPosted: Wed Jun 21, 2006 9:19 am   Post subject: (No subject)

[Gandalf] wrote:
No problem. Maybe it's a sign of Delos' clairvoyance spreading. Wink


About time too! What's the point of answering questions if you can't pre-empt other question's answers in the process? Wink
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: