For money that doesn't involve fractions of cents, you might best use fixed point. Basically, fixed point is an integer with an implied decimal point. So the value 1234 would actually be 12.34. To add or subtract fixed point numbers, it is just like adding or subtracting integers, just use + and -. To multiply, you need to divide the result by 100 (add 50 first if rounding is important). To divide, if you don't need rounding, you can just multiply the dividend by 100, then divide. If you do need rounding, then multiply the dividend by 1000, add 5, then divide by 10
'To add and subtract, just use + and - normally
Function FP_Multiply:Int(Value1:Int,Value2:Int,Round:int = True)
Local Result:Int = Value1 * Value2 'Multiply the values together
If Round Then Result :+ 50 'If rounding the result to nearest penny, just add 50
Result :/ 100 'Divide the result by 100
Return Result 'return the result
End Function
Function FP_Divide:Int(Dividend:Int, Divisor:Int,Round:Int = True)
Local Result:Int
If Round
Dividend :* 1000 'Multiply by 1000
Else
Dividend :* 100 'Multilpy the Dividend by 100 for better precision
End If
Result = Dividend/Divisor 'Divide
If Round
Result = (Result + 5) / 10 'If rounding, Add 5 and devide by 10
End If
Return Result 'Return the result
End Function
To print, just print all but the right two numbers, decimal point, then the right two numbers
Function PF_ToString:String(Number:Int)
Local Temp:String = String(Number) 'Convert the whole number to a string
Local Result:String = Temp[..Temp.Length - 2] 'Extract all but the right two numbers
Result :+ "." 'Add a decimal point
Result :+Temp[Temp.Length-2..] 'Add the rest
Return Result
End Function