Computer Science Canada rounding numbers in GUI.

Author:  Bruski [ Mon Jun 16, 2003 7:21 am ]
Post subject:  rounding numbers in GUI.

anyone know how to round the numbers to two decimal places....usually its :6:2 second being the amount of decimal places to display but im new to the GUI. commands and got no clue as to where to put this...any suggestions

thx again

 Author: Andy [ Mon Jun 16, 2003 9:27 am ] Post subject: just round it ur self, multiply the number by 100, div it by 1 and then / it by 100

Author:  Homer_simpson [ Mon Jun 16, 2003 11:19 am ]
Post subject:

use my function to turn them into what you want
 code: function decimal (r : real, i : int) : real     var rs := realstr (r, 1)     var ts := ""     var c := 1     var c2 := 0     var dec := false     loop         if rs (c) not= "." then             ts += rs (c)         else             ts += "."             dec := true         end if         exit when c = length (rs) or c2 = i         c += 1         if dec then             c2 += 1         end if     end loop     result strreal (ts) end decimal put decimal (32.231321, 2)

 Author: Bruski [ Mon Jun 16, 2003 11:50 am ] Post subject: im confused...where do i put that...?

Author:  Homer_simpson [ Mon Jun 16, 2003 1:04 pm ]
Post subject:

put
 code: function decimal (r : real, i : int) : real     var rs := realstr (r, 1)     var ts := ""     var c := 1     var c2 := 0     var dec := false     loop         if rs (c) not= "." then             ts += rs (c)         else             ts += "."             dec := true         end if         exit when c = length (rs) or c2 = i         c += 1         if dec then             c2 += 1         end if     end loop     result strreal (ts) end decimal

at the top of your program...
this is how the functionworks

decimal(num:real,dec:int)

num is the number that you want to round
and dec is the number of decimals you want it to have

so if you put:
put deimal(100.5555,1)
the out put will be 100.5

 Author: JayLo [ Mon Jun 16, 2003 1:41 pm ] Post subject: wait... i used frealstr to do something like this... i'll try and find an example.

 Author: Andy [ Mon Jun 16, 2003 2:26 pm ] Post subject: there is such an command? what does it do? too lazy to go to turing and type and press F9

 :