Mojo3d works, so there must be something to do with the GLWindow and the GL stuff that’s not correct anymore
]]>I’ll do a quick hack and report back…
]]>They’re inaccurate by design as they have to work within a set number of bits.
Try this simple, obvious division:
|
1 2 3 4 5 6 7 8 9 10 11 |
Namespace myapp #Import "<std>" Using std.. Function Main() Print 1.0 / 10.0 End |
Here, it prints 0.10000000000000001, but the result may vary on different platforms/targets, and this is to be expected for floating point numbers — they simply can’t represent all decimal numbers accurately.
Anyway, you’ve figured out a solution that looks good for currency.
]]>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
Class Currency ' Store the whole and fractional parts as integers Private Field wholeNumber:Int Field fractionalNumber:Int Public Method New(number:String="0.00") Local decimal:=number.Find(".",0) wholeNumber=Cast<Int>(number.Mid(0,decimal)) '0.00 fractionalNumber=Cast<Int>(number.Mid(decimal+1,number.Length-1-decimal)) End Method New(whole:Int,fractional:Int) wholeNumber=whole fractionalNumber=fractional End Method Get:String(prepend:String="") Return prepend+wholeNumber+"."+LPad(fractionalNumber) End Method LPad:String(num:Int) If num<10 Then Return "0"+num Else Return num Endif End ' Currency Operator Overloads Operator+:Currency(rhs:Currency) Local whole:=wholeNumber+rhs.wholeNumber Local dec:=fractionalNumber+rhs.fractionalNumber If dec>99 Then dec-=100 whole+=1 Endif Return New Currency(whole,dec) End Operator-:Currency(rhs:Currency) Local whole:=wholeNumber-rhs.wholeNumber Local dec:=fractionalNumber-rhs.fractionalNumber If dec<0 Then dec+=100 whole-=1 Endif Return New Currency(whole,dec) End Operator To:String() Return Get("$") End End Function Main() Local a:=New Currency("1.99") Local b:=New Currency("10.00") Local c:=a+b Print c End |