Format strange results

The code below returns:

Xojo Code:

Format(aStory_FI.Length,"#,###,###") + " Bytes" + EndOfLine

Returned format:
Size: 60527 644 Bytes

Expected format:
Size: 60 527 644 Bytes

Environment:
Current Xojo version
macOS High Sierra (French)
(standard locale for French)

PS: to be sure, I copy / paste the comma in the Format “mask”…

Looks like a bug, try ###,### as a workaround.

Probably the system is returning &ua0 (non-break space, utf8 0xC2 0xA0 (c2a0)) and it is causing some internal mess with the Xojo mask handling, not expecting to deal with such kind of value.
Report the bug.

What happens if :

Format(aStory_FI.Length,"###,###,##0") + " Bytes" + EndOfLine

Because your example value overflowed your previous mask.

@Julian:

it works !

@Rick_Araujo:
Your answer is creative. It would have been easy to check in the debugger.
There is a mess, but it is elsewhere… I am searching for the last three hours, polishing my code in between when I am at ideas changes loss…

@Rick_Araujo:

Writing about creative answer apparently unlocked my brain. I found a creative way to remove the mess and my code (the other part I was debugging since… hours ago).
…and I was watching TV during the same time. ;-:slight_smile:

I reported the bug for you Emile <https://xojo.com/issue/63721>

3 Likes

We disagree here:

                                             'Expected    Actual
system.DebugLog(format(0, "0,###"))          '0,000       00 <<<<
system.DebugLog(format(0, "0###"))           '0000        00 <<<<

'Case 44624
system.DebugLog(format(0, "00.#"))           '00          00. <<<<
system.DebugLog(format(0.0, "#.##"))         '<empty>     0. <<<<

system.DebugLog(format(0, "#"))              '<empty>     0 <<<<
system.DebugLog(format(0, "0"))              '0           0

What I do expect:

system.DebugLog(format(0, "0,###"))          'Exception Error, Invalid mask           00 <<<<
system.DebugLog(format(0, "0###"))           'Exception Error, Invalid mask           00 <<<<

'Case 44624
system.DebugLog(format(0, "00.#"))           '00.         00. <<<<
system.DebugLog(format(0.0, "#.##"))         '<empty>     <empty> <<<<

system.DebugLog(format(0, "#"))              '<empty>     <empty> <<<<
system.DebugLog(format(0, "0"))              '0           0

The “0” mask should be only used as a sequence before and after the decimal point without intervening “#” (remove if 0) in the middle. Then “#” can be after the zeros, on the right side, after the decimal point, or after the zeros, to the left side, after the decimal point. So:

Valid:
####0
###0.
###0.###
###0.00
###0.00##

Invalid:
0###
0###0
0.0##0
etc.
1 Like

Thank you Julian.

#Rick_A:
Your first two lines does not have sense:
0,### is non sense and resut… too
0 is 0, not 0000 nor 00

If your numbers are numerical values.
Use 0 in the mask if you want zeroes…

I don’t get what you’re saying, but ok. What I said has perfect sense.

Interesting, do we get the same with Double.ToString(“0,###”) etc ?

Interestingly I made a test

Var d As Double = 0
Var s As String = d.ToString("0,###") // Wrong

And the behavior was as expected, an exception.

And the other way around works, also as expected:

Var d As Double = 0
Var s As String = d.ToString("#,##0") // Ok

Just remember that Format(fmt) uses the current locale as output, and var.ToString(fmt) uses raw locale, it is, the decimal point is always “.”, and no thousands separator.

1 Like

I will ask the question differently:
your mask seems to ask 3 digits after the decimal. Two of them are “optional” (can be omited), and the last one have to be 0 if no other value exists.

Strange demand.

Care to explain its use ?

OK: some people can code that way (to know if this works IMHO), but in real world, what can be its use ?

This does not exists:
https://documentation.xojo.com/api/code_execution/to.htmlString

Searching for ToString returns a ton of links; example:
https://documentation.xojo.com/api/data_types/currency.html#currency-tostring

Converts a currency value to a String value using the specified locale.

Comma is not the “decimal” point, it’s the thousands’ separator.

Argh, I’ve made an error. Sorry.

No problem. :wink:

It is my fault:I was not watching TV at the same time… (temporary no usb slot available for that).