Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 real number to string converison
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
metal_hed




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Feb 18, 2004 6:11 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
recneps




PostPosted: Thu Feb 19, 2004 5:42 pm   Post subject: (No subject)

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

and then intstr it Smile
Tony




PostPosted: Thu Feb 19, 2004 5:46 pm   Post subject: (No subject)

code:

var number : real := 123.456789
var text : string

text := intstr(round(number*10))
put text(1..*-2),".",text(*-1..*)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
octopi




PostPosted: Thu Feb 19, 2004 6:47 pm   Post subject: (No 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)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: