
-----------------------------------
metal_hed
Wed Feb 18, 2004 5:53 pm

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? :?

-----------------------------------
Tony
Wed Feb 18, 2004 6:11 pm


-----------------------------------

realstr ( r : real, width : int ) : string


thought the width part doesn't really seem to do anything :? You might have to use index() to locate decimal point and round the string yourself if you have to

-----------------------------------
recneps
Thu Feb 19, 2004 5:42 pm


-----------------------------------
if you need to roundit, just 
round(variable)
and then intstr it :)

-----------------------------------
Tony
Thu Feb 19, 2004 5:46 pm


-----------------------------------

var number : real := 123.456789
var text : string

text := intstr(round(number*10))
put text(1..*-2),".",text(*-1..*)


-----------------------------------
octopi
Thu Feb 19, 2004 6:47 pm


-----------------------------------
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)
