change decimal print

BlitzMax Forums/BlitzMax Beginners Area/change decimal print

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This takes care of Scientific Notation as well...ie. 5e+021 :
strict

Local a:Float = 0.00092304
Print a+" -> "+FloatToFixedPoint(a)
Local b:Float = 120592345792834.0235234
Print b+" -> "+FloatToFixedPoint(b)
Local c:Float = 1.0/3.0
Print c+" -> "+FloatToFixedPoint(c)

Function FloatToFixedPoint:String(f:Float,decimals:Int=3)

	Local i:Long = (10^decimals)*f
	Local value:String = String.fromlong(i)
		
	If value.length<=decimals
		Return "0."+(RSet("",decimals-value.length)).Replace(" ","0")+value
	Else
		Return value[0..value.length-decimals] + "." + value[value.length-decimals..value.length]  
	EndIf
	
End Function 
Slices and string methods ROCK!