Computer Science Canada

having two decimal places for realstr function

Author:  tristanbryce7 [ 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

Author:  Dreadnought [ 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

Author:  tristanbryce7 [ 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 ;(

Author:  Tony [ Fri Jan 18, 2013 7:58 pm ]
Post subject:  RE:having two decimal places for realstr function

in which way did it not work?

Author:  tristanbryce7 [ 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

Author:  tristanbryce7 [ 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

Author:  Tony [ 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

Author:  tristanbryce7 [ 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

Author:  evildaddy911 [ 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

Author:  tristanbryce7 [ 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

Author:  evildaddy911 [ 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


: