From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I format a large number to have comma separators?

Mikael,

Two problems:

Results are unexpected ...
  • If there are more than 2 decimal digits
    (e.g. 8000000000.00 turns into 8,000,000,000.,000 with three decimal digits)

  • If the number is negative and the number of integer digits is divisible by 3:
    (e.g. -800000000.00 turns into -,800,000,000.00).

    It is also probably not a good idea to set "use system decimal point to true". In Europe you'll get a decimal comma which is indistinguishable from the thousands separator. Setting this to FALSE ensures that we get a decimal point.

    I tend to do these operations on U8 arrays instead of strings. One possible solution is attached (LabVIEW 7.0). (It passes the above tests, but there is no guarantee that it is perfect 😉 There are many ways to do this.)
  • 0 Kudos
    Message 11 of 29
    (4,103 Views)
    Hey guys, interesting discussion, here's my own two cents, i think it works for all situations. Let me know!
     
    Liam
    Message 12 of 29
    (3,856 Views)

    @LiamK wrote:
     
    Hey guys, interesting discussion, here's my own two cents, i think it works for all situations. Let me know!
     
    Liam


    Despite 9 years passing and many requests to NI to build comma separation into indicators themselves (such as this), your solution remains the best way to do it.  Nice job making it so streamlined.

     

    I have one question.  Can you explain what the purpose of this part of the pattern is?  I cannot find any clues in labview's help.

    [~\2E\2C]

     

    I replaced it wth this and it still works, as far as I can tell.

    [~.]

     

    Thanks,

    Mike

    0 Kudos
    Message 13 of 29
    (2,882 Views)

    MarredCheese wrote:

    [~\2E\2C]


    2E is the period and 2C is the comma.  These might be special characters for regular expressions, therefore you will need to go by their hex value.  The comma is often used as the decimal separator instead of the period in some countries (like Germany).


    GCentral
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    "Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
    0 Kudos
    Message 14 of 29
    (2,864 Views)

    @crossrulz wrote:

    MarredCheese wrote:

    [~\2E\2C]


    2E is the period and 2C is the comma.  These might be special characters for regular expressions, therefore you will need to go by their hex value.  The comma is often used as the decimal separator instead of the period in some countries (like Germany).


    Oh, ok.  Thanks!

     

    I attached a minorly updated version.  I changed that part of the string to [~,.] since it's more readable.  I also made it neater, gave it an icon, made precision into an input, and wired up the connector pane so it can be used as a subVI.

     

     

    Message 15 of 29
    (2,816 Views)

    Very interesting posting.

    Can somebody convert the last example for LV2012?

    0 Kudos
    Message 16 of 29
    (2,732 Views)

    Isn't there a Number to string format (%9.3f) style of conversion?  Your VI inserts a comma every 3 digits, but it is also putting a comma at the beginning, Example:  

     

    186282.396 = ,186,282.396

     

    0 Kudos
    Message 18 of 29
    (2,143 Views)

    That VI is much better, however it keeps trimming the decimal numbers to 2 digits, How do I control that.  You also know that it is also proper to group digits in 3 digit groups with comma's as well.  So if I have a long decimal number like 3.1415926 it should read 3.141,592,6

    0 Kudos
    Message 19 of 29
    (2,142 Views)

    @emw129 wrote:

    That VI is much better, however it keeps trimming the decimal numbers to 2 digits, How do I control that.  You also know that it is also proper to group digits in 3 digit groups with comma's as well.  So if I have a long decimal number like 3.1415926 it should read 3.141,592,6


    Which VI's are you referring to in your last 2 messages?  When you reply to an older message you should add that message using the quote button so we know what you are talking about.

     

    But JB's VI in message 17 seems to work properly.

     

    And no it is not proper to put commas in the decimal portion of the number.  That is something I've never seen before.

     

    But I did come across another idea in the Idea Exchange, a duplicate of the one I posted on your other thread, where Henrik Volkers posted a VI that did to a separator in the decimal portion.  He defaulted his to a space rather than a comma.  But that is easy to change and seemd to work.

     

    https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Format-into-string-with-thousands-separator/idi-p/112...

    0 Kudos
    Message 20 of 29
    (2,136 Views)