Page 1 of 1

Posted: Sun Oct 27, 2002 11:45 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

this prints "103" in the debug console, is there any way i can convert 103.88 to a string which reads "103.88" without rounding it?

Code: Select all

Debug Str(103.88)

Posted: Mon Oct 28, 2002 12:10 am
by BackupUser
Restored from previous forum. Originally posted by PB.

Unlike other BASICs, in PureBasics you use the StrF command when
dealing with floats. So change Str(103.88) to StrF(103.88) to do
it; however, you'll notice that it prints 103.879997 too, so if this
bothers you (until Fred fixes it) then use this procedure instead:

Code: Select all

; Procedure originally by Don.
;
Procedure.s StrFloat(number.f, places.l)
  r=Pow(10,places) : vf.f=number*r : vs.s=Str(vf)
  rs.s=Left(vs,Len(vs)-places)+"."+Right(vs,places)
  ProcedureReturn rs
EndProcedure
;
Debug StrFloat(103.88, 2) ; 2 = # of decimal places.
PB - Registered PureBasic Coder

Posted: Mon Oct 28, 2002 5:40 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

thanks thats very helpful :) i must of missed StrF in the docs.