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

Username:   Password: 
 RegisterRegister   
 having two decimal places for realstr function
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tristanbryce7




PostPosted: Fri Jan 18, 2013 6:19 pm   Post subject: having two decimal places for realstr function

Hey, i was hoping if anyone knew the method to draw a "real" number in turing using Font.Draw but have the output in to only 2 decimals
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Fri Jan 18, 2013 6:43 pm   Post subject: Re: having two decimal places for realstr function

Instead of using realstr use frealstr or erealstr
tristanbryce7




PostPosted: Fri Jan 18, 2013 7:51 pm   Post subject: Re: having two decimal places for realstr function

i looked at the syntax and tried it accordingly but it didnt work ;(
Tony




PostPosted: Fri Jan 18, 2013 7:58 pm   Post subject: RE:having two decimal places for realstr function

in which way did it not work?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tristanbryce7




PostPosted: Fri Jan 18, 2013 9:19 pm   Post subject: Re: having two decimal places for realstr function

sorry. i am on mobile lol. as soon as i get on comp ill tell you
tristanbryce7




PostPosted: Fri Jan 18, 2013 9:24 pm   Post subject: Re: having two decimal places for realstr function

Ok, so I put
frealstr (14.245,4,1)
but it said expression is not a procedure. I'm pretty sure i got the synntax wrong Sad
Tony




PostPosted: Fri Jan 18, 2013 9:25 pm   Post subject: RE:having two decimal places for realstr function

and what do you get? How is that different from what you expected to get?

edit:
right, this is a function that is returning a result, and Turing forces you to do something (anything) with the result. For example, you can print it to screen
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tristanbryce7




PostPosted: Fri Jan 18, 2013 9:40 pm   Post subject: Re: having two decimal places for realstr function

I have no clue how to output the result . I have

frealstr (14.245,4,1) so far, but I try out putting it , but I dont know how to combine this frealstr with a "put" statement
Sponsor
Sponsor
Sponsor
sponsor
evildaddy911




PostPosted: Fri Jan 18, 2013 10:23 pm   Post subject: RE:having two decimal places for realstr function

Easy: putting "put" before any expression will output the result to the screen
Eg
put 45 * round (2.36)

The window now has "90" written in the TL corner
tristanbryce7




PostPosted: Sat Jan 19, 2013 10:24 am   Post subject: Re: having two decimal places for realstr function

I feel like an absolute idiot lol, never thought it could've been so simple Sad
evildaddy911




PostPosted: Sat Jan 19, 2013 11:09 am   Post subject: Re: having two decimal places for realstr function

when i want to output a number rounded to a certain # of decimals, i use this function:

Turing:

function roundStr (num : real, places : int) : string
    var final : string
    final := intstr (round (num * 10 ** places))
    final := final (1 .. * -places) + "." + final (* -places + 1 .. *)
    result final
end roundStr
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  [ 11 Posts ]
Jump to:   


Style:  
Search: