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

Username:   Password: 
 RegisterRegister   
 Some help with real varibles...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
josh_65665




PostPosted: Mon Sep 15, 2008 12:02 pm   Post subject: Some help with real varibles...

Lets say i have a varible thats a real right but i dont want it to be long like for example i want 12554.56 instead of 12554.562342534

is there a way to get rid of extra digits
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Sep 15, 2008 12:19 pm   Post subject: RE:Some help with real varibles...

round()
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
The_Bean




PostPosted: Mon Sep 15, 2008 5:14 pm   Post subject: Re: Some help with real varibles...

I you really want to "get rid" of extra numbers you can convert to a string, find the decimal position then cut off anything past 2 places after the decimal then convert back to real.

An easier method would be

num:= round( num*100)/100
lordroba




PostPosted: Mon Sep 15, 2008 6:40 pm   Post subject: Re: Some help with real varibles...

Or perhaps you mean something like this...

Turing:

var a := 12554.562342534
put a : 6 : 2


The first number is the width of the string, the second number is how many decimals you want.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: