Computer Science Canada

real number to string converison

Author:  metal_hed [ Wed Feb 18, 2004 5:53 pm ]
Post subject:  real number to string converison

I'm making a menu and want to add the total of a calculation in another font besides the default one. When i use the Draw.Font command it will only accept strings. Is there a way to comehow convert the total, which is a real number, to a string so the font.draw will accpet it? Confused

Author:  Tony [ Wed Feb 18, 2004 6:11 pm ]
Post subject: 

Quote:

realstr ( r : real, width : int ) : string


thought the width part doesn't really seem to do anything Confused You might have to use index() to locate decimal point and round the string yourself if you have to

Author:  recneps [ Thu Feb 19, 2004 5:42 pm ]
Post subject: 

if you need to roundit, just
code:
round(variable)

and then intstr it Smile

Author:  Tony [ Thu Feb 19, 2004 5:46 pm ]
Post subject: 

code:

var number : real := 123.456789
var text : string

text := intstr(round(number*10))
put text(1..*-2),".",text(*-1..*)

Author:  octopi [ Thu Feb 19, 2004 6:47 pm ]
Post subject: 

code:
var r:real:=3.14159265859

function real2str (r:real, d:int) :string
  var s:string
  var nd:int:=d
  if(nd >= 9) then
    nd:=8
  end if
  var temp:real:= (r - floor(r)) * 10**(nd)
  s:=intstr(floor(r)) + "." + intstr(round(temp))
  result s
end real2str

put real2str(r,9)
% real2str(real number, number of digits after decimal)


: