# Format strange results

**URL:** <https://forum.xojo.com/t/format-strange-results/61284>\
**Category:** General\
**Created:** [February 18, 2021, 1:25pm UTC](https://forum.xojo.com/t/format-strange-results/61284 "2021-02-18T13:25:17Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 18, 2021, 1:25pm UTC](https://forum.xojo.com/t/format-strange-results/61284/1 "2021-02-18T13:25:17Z")

</div>

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”…

---

<div class="post-metadata">

**Author:** ![anon20074439](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@anon20074439](https://forum.xojo.com/u/anon20074439)\
**Post date:** [February 18, 2021, 1:39pm UTC](https://forum.xojo.com/t/format-strange-results/61284/2 "2021-02-18T13:39:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 18, 2021, 1:47pm UTC](https://forum.xojo.com/t/format-strange-results/61284/3 "2021-02-18T13:47:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 18, 2021, 1:56pm UTC](https://forum.xojo.com/t/format-strange-results/61284/4 "2021-02-18T13:56:32Z")

</div>

> [@Emile\_Schwarz](#):
>
> `Format(aStory_FI.Length,"#,###,###") + " Bytes" + EndOfLine`

What happens if :

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

```

Because your example value overflowed your previous mask.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 18, 2021, 1:56pm UTC](https://forum.xojo.com/t/format-strange-results/61284/5 "2021-02-18T13:56:46Z")

</div>

@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…

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 18, 2021, 2:40pm UTC](https://forum.xojo.com/t/format-strange-results/61284/6 "2021-02-18T14:40:26Z")

</div>

@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. ;-🙂

---

<div class="post-metadata">

**Author:** ![anon20074439](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@anon20074439](https://forum.xojo.com/u/anon20074439)\
**Post date:** [February 18, 2021, 3:05pm UTC](https://forum.xojo.com/t/format-strange-results/61284/7 "2021-02-18T15:05:59Z")

</div>

I reported the bug for you Emile \<[https://xojo.com/issue/63721](https://xojo.com/issue/63721)\>

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 18, 2021, 3:37pm UTC](https://forum.xojo.com/t/format-strange-results/61284/8 "2021-02-18T15:37:23Z")

</div>

We disagree here:

```auto
                                             '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:

```auto
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:

```auto
Valid:
####0
###0.
###0.###
###0.00
###0.00##

Invalid:
0###
0###0
0.0##0
etc.

```

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 18, 2021, 4:10pm UTC](https://forum.xojo.com/t/format-strange-results/61284/9 "2021-02-18T16:10:52Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 18, 2021, 8:33pm UTC](https://forum.xojo.com/t/format-strange-results/61284/10 "2021-02-18T20:33:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [February 18, 2021, 8:50pm UTC](https://forum.xojo.com/t/format-strange-results/61284/11 "2021-02-18T20:50:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 18, 2021, 11:35pm UTC](https://forum.xojo.com/t/format-strange-results/61284/12 "2021-02-18T23:35:18Z")

</div>

Interestingly I made a test

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 19, 2021, 10:28am UTC](https://forum.xojo.com/t/format-strange-results/61284/13 "2021-02-19T10:28:56Z")

</div>

> [@Rick\_Araujo](#):
>
> `"#,##0"`

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](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](https://documentation.xojo.com/api/data_types/currency.html#currency-tostring)

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

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 19, 2021, 11:35am UTC](https://forum.xojo.com/t/format-strange-results/61284/14 "2021-02-19T11:35:22Z")

</div>

> [@Emile\_Schwarz](#):
>
> your mask seems to ask 3 digits after the decimal

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

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 19, 2021, 5:09pm UTC](https://forum.xojo.com/t/format-strange-results/61284/15 "2021-02-19T17:09:20Z")

</div>

Argh, I’ve made an error. Sorry.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [February 19, 2021, 5:12pm UTC](https://forum.xojo.com/t/format-strange-results/61284/16 "2021-02-19T17:12:48Z")

</div>

No problem. 😉

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [February 19, 2021, 6:06pm UTC](https://forum.xojo.com/t/format-strange-results/61284/17 "2021-02-19T18:06:32Z")

</div>

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