Author |
Message |
tristanbryce7
|
Posted: 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
|
|
|
Dreadnought
|
Posted: 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
|
Posted: 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
|
Posted: Fri Jan 18, 2013 7:58 pm Post subject: RE:having two decimal places for realstr function |
|
|
in which way did it not work? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
tristanbryce7
|
Posted: 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
|
Posted: 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 |
|
|
|
|
|
Tony
|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
tristanbryce7
|
Posted: 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
|
|
|
evildaddy911
|
Posted: 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
|
Posted: 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 |
|
|
|
|
|
evildaddy911
|
Posted: 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
|
|
|
|
|
|
|
|