I wonder if they are using platform specific code in Format under the hood …
if so and the rounding IS different because of it, that is one HUGE reason NOT to use platform specific code for non UI stuff for an X-Platform product!
Lots of subtle bugs could be introduced because of those types of things!
BTW try 11.5 on both platforms to see if one is following the even-odd rounding rules or both behave the same way with an odd number.
I frankly dont care what kind of rounding is used as long it is consistent across platforms. As a developer of accounting software its incredibly embarrassing to have to face my clients on something so basic.
I wonder if this is something in the C libraries on each platform
I cant say which functions might be in use for the format function but you might try sprintf or snprintf on each and see if that results in a similar difference
Either way it should be reported as an inconsistency across platforms that maybe Xojo can fix
[quote=471677:@Markus Rauch]a double of 10.5 looks like this
10.4999999999998
or
10.500000000001
i would print the real values first.[/quote]
fwiw 10.5 IS a double that can have an exact representation since the .5 is a precise power of 2 (lots arent)
10 = 2^2 + 2^1
.5 = 1/(2^1)
in this case 10.5 can be precisely represented in a IEEE 754 double without the normal error
really doesnt matter what Xojo prints
the conversion to a string form for printing could be subtly flawed resulting in what you saw
or the conversion from the literal to a double could be flawed again resulting in a subtle error
either way 10.5 is representable precisely in either a single or double floating point format
that we get very different rounding on a value that SHOULD be precisely representable is problematic as Richard pointed out in his prior post
This is true, but using the currency type, the result is the same. I believe that Xojo converts the currency type to double within the Format function.
Whatever the reason for this behavior, Xojo should fix it so that Format works consistently across platforms.
rounding like this becomes a non-issue
and when you “print” you just turn the int64 into a string and insert the correct decimal marker at whatever position is needed (same for thousands if you need those)
for instance if you used an int64 and wanted 4 decimals then you would use str or format to get the integer as a string (no decimals)
and then insert a decimal point so you have 4 decimal places
conversion of user values to this type amounts to adding 0’s to pad out so you have 4 decimal places
you have to be careful of using VAL though as once it reaches certain values you start to lose low digits as doubles have a limited ranges that you start to exceed with really large values
[quote=471682:@Norman Palardy]
in this case 10.5 can be precisely represented in a IEEE 754 double without the normal error
its
01000001001010000000000000000000[/quote]
MY BAD !!! this is the SINGLE format not double
a double is
0x4025000000000000 = 01000000 00100101 00000000 00000000 00000000 00000000 00000000 00000000
and the following code takes that binary and turns it into a double in xojo which is precise
Dim mb As New memoryblock(8)
mb.LittleEndian = False
' mb.doubleValue(0) = 10.5
mb.uint8value(0) = &b01000000
mb.uint8value(1) = &b00100101
mb.uint8value(2) = &b00000000
mb.uint8value(3) = &b00000000
mb.uint8value(4) = &b00000000
mb.uint8value(5) = &b00000000
mb.uint8value(6) = &b00000000
mb.uint8value(7) = &b00000000
Dim d As Double = mb.DoubleValue(0)
Break