Function round#(variable#,decimales) dec# = (variable# - Int(variable#))*10 dec# = Int(dec) dec# = (Left(dec,decimales+1)) dec# = dec# *.1 variable# = Int(variable#) + Float(dec#) Return variable# End Function
If Abs(variable - Int(variable)) < .01 Then variable# = Int(variable) End If
'Example output prints 2.12Local d:Double = 2.1234567Print RoundDouble(d)Function RoundDouble:String(d:Double, precision:Int=2) Local s:String Select precision Case 0 Return String( Int(d + 0.5) ) Case 1 s = String(d + 0.05) Case 2 s = String(d + 0.005) Default s = String(d + 0.0005) EndSelect Local a:String[], decimal:String If s.contains(".") Then a = s.split("."); decimal = "." ElseIf s.contains(",") a = s.split(","); decimal = "," Else Notify "Error: RoundString() failed with " + s + ".", True; Return s EndIf Return (a[0] + decimal + Left( a[1], precision) )EndFunction