New framework and ToText formatting

I notice that, unlike Format, ToText(Xojo.Core.Locale.Raw, “#,###;-#,###;”) fails to blank a zero value. I’ll file this in Feedback if others confirm this for me.

Create a TextField1 and use this to test in a button action:

Dim value As Integer = Integer.Parse(TextField1.Text.ToText) MsgBox value.ToText(Xojo.Core.Locale.Raw, "#,###;-#,###;")

Another button for testing Format instead:

MsgBox Format(Val(TextField1.Text), "#,###;-#,###;")

After testing this I would lean toward the ToText behavior.

But

"#;-#;"

has been a way to hide 0 values with Format. This sounds like it breaks a traditional way formatting is to be understood.

https://documentation.xojo.com/index.php/Format:
“The formatSpec can be made up of up to three formats separated by semicolons. The first format is the format to be used for positive numbers. The second format is the format to be used for negative numbers and the third format is the format to be used for zero.”

.totext is using the proper standards now:

“# Number Yes Digit, zero shows as absent”

This still shows the 0 numeral when the value is 0:

Dim value As Integer = Integer.Parse(TextField1.Text.ToText)
MsgBox value.ToText(Xojo.Core.Locale.Raw, “#,###;-#,###;0”)

All I can say is that http://developer.xojo.com/integer$ToText doesn’t say anything like that, so ¯\(?)

I’m not arguing either way, I’m just saying that personally I would want to keep that 0 around, and I’ll remove it if I don’t want it.

Ok. I’m glad I posted this here first, instead of Feedback. Looks like new standard is to never blank a 0 value via a formatSpec, and I’ll just have to manually code that when needed.

[quote=369815:@JulianS].totext is using the proper standards now:

“# Number Yes Digit, zero shows as absent”[/quote]

Now that I think about this, doesn’t that mean that if the digit is 1-9, it will show, and if 0, it will not?

If a digit is there, show it, if value is “” show 0

More information here:
http://unicode.org/reports/tr35/tr35-4.html#Number_Format_Patterns

It say:

  • ‘1’ through ‘9’ indicate rounding.
  • Digit, zero shows as absent

Edit: Julian already linked the standards

I get it now. I had the logic order backwards. I thought that meant that if the value was 0 then show “”. But it’s the other way around.

Looking over that online doc, I think it only evaluates the first 2 parts of

“###;-###;”

I don’t think it evaluates the 3rd part at all. That is, unlike Format, there is no Zero format (the third part).

And just to confuse matters, I prefer the # should return “” method, but xojo chose to go with 0 so /shrug

I’m used to .net doing it that way.

http://www.mobzystems.com/online/format-tester/

Try

[{0,10:#}] with 0 as your value for part 2

[quote=369825:@Ralph Alvy]I get it now. I had the logic order backwards. I thought that meant that if the value was 0 then show “”. But it’s the other way around.

Looking over that online doc, I think it only evaluates the first 2 parts of

“###;-###;”

I don’t think it evaluates the 3rd part at all. That is, unlike Format, there is no Zero format (the third part).[/quote]
Hello Ralph, I’m learning here, what I read is:

  • Format maybe use the 3 parts
  • the new framework (ToText) format use the standard that is only 2, for positive numbers then ; then sub pattern for negative number

I’ll have to do some tests to learn more about this.

After a few tests I found out that your code:

MsgBox Format(Val(TextField1.Text), "#,###;-#,###;")

actually has 3 parts

  • #,###
  • -#,###
  • “”
    that’s why nothing is displayed on the MsgBox. I changed the code to:
MsgBox Format(Val(TextField1.Text), "#,###;-#,###")

now it only has 2 parts and MsgBox show 0 if there is nothing or 0 inside the TextField1

[quote=369828:@Alberto De Poo]After a few tests I found out that your code:

MsgBox Format(Val(TextField1.Text), "#,###;-#,###;")

actually has 3 parts

  • #,###
  • -#,###
  • “”
    that’s why nothing is displayed on the MsgBox. I changed the code to:
MsgBox Format(Val(TextField1.Text), "#,###;-#,###")

now it only has 2 parts and MsgBox show 0 if there is nothing or 0 inside the TextField1[/quote]

That’s my the point. With Format, I could add that 3rd part and make sure that 0 values are displayed as “”. There is no way to do that with the newer formatSpec. For now, I’m doing things like this:

MsgBox If(Integer.Parse(TextField1.Text.ToText) = 0, "", Integer.Parse(TextField1.Text.ToText).ToText)

Sorry, I’m just trying to learn and understand new things.

From what I read, the format is different from Format (uses 3 parts), and the standard that now uses the new .ToText format only uses 2 and will show 0.

[quote=369838:@Alberto De Poo]Sorry, I’m just trying to learn and understand new things.

From what I read, the format is different from Format (uses 3 parts), and the standard that now uses the new .ToText format only uses 2 and will show 0.[/quote]

That’s what I’m seeing also.

Thank you Ralph, I didn’t know that I can use an If statement with MsgBox.

Testing your code and what you want to do, this is the simplest way I can find to do it (if having ‘value’):

Dim value As Integer = Integer.Parse(TextField1.Text.ToText) MsgBox if(value=0,"",value.ToText(Xojo.Core.Locale.Raw, "#,###"))
From what I read, the negative part will use the symbol - if nothing is provided and will follow the pattern from positive value even if other pattern is provided.

I didn’t understand this the first time I read it. I think I do know, but I don’t see a difference between #,##0 and #,###. If the value is 0, both will show 0, if there is no value, then both will display 0, but that’s the way the standard works.

It’s use of the new inline if statement they introduced a while back. The only documentation of it that I know of is this blog post: https://blog.xojo.com/2014/03/12/using-the-new-if-operator

I just wanted to also let you know that I very much appreciate how much you’re willing to learn, and it’s why I’m always happy to help you when you have questions. Never be sorry for wanting to learn!

I only recently saw someone use IF as 3-part operator and now make extensive use of it.