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?

I have numbers that are very large, i.e., in the billions. I want to format the display to show comma separators.

For example:
8000000000 => 8,000,000,000

Is there an easy way to do this?
Message 1 of 29
(9,267 Views)
Robert,

There is no way (to my knowledge) to include comma separators in a numeric control or indicator in LabVIEW. If you want commas, you will need to use a string. I have attached an example VI to this post that demonstrates how I would include comma separators in a large number string. There might be an easier way, but this was the first thing that came to mind.

I hope this helps. Good luck with your application, and have a pleasant day.

Sincerely,
Darren N.
NI Applications Engineer
0 Kudos
Message 2 of 29
(9,262 Views)
Good solution Darren. Just a short note: This VI works fine as long as one needs commas to separate groups of "three zeroes". If one want a commas to separate groups of three digits, this VI will fail. But this VI can easily be tailored to be more general. /Mikael
0 Kudos
Message 3 of 29
(9,262 Views)
Mikael,

You're right! I was in such a hurry to write the quick example I didn't even think about numbers without zeroes. The fix was easy, though...here's a VI that will put commas in for *any* number greater than 999.

Thanks for bringing it to my attention.

Darren N.
Message 4 of 29
(9,262 Views)
Darren,

Thanks for the code. These small vi's are great examples of small chores that are sometimes required by data displays. I appreciate the effort and the help. Also helps me to understand LabVIEW.

Bob
0 Kudos
Message 5 of 29
(9,262 Views)
Glad to help, Bob. I think the Developer Exchange is one of the best ways for LabVIEW users, from beginning to advanced, to gain valuable insights from other users...just make sure you understand everything that's going on in the block diagram so as to further strengthen your LabVIEW programming skills.

Good luck with your application, and make sure to use the Developer Exchange for any programming questions you have in the future.

Sincerely,
Darren N.
0 Kudos
Message 6 of 29
(9,262 Views)
Darren,
Thanks for your support here. Your modification was very neat! Your use of "[0-9][0-9][0-9]" made things very compact! Impressing!

However, I happened to notice yet another tiny thing. Your VI fail for numbers that have 3, 6, 9, 12, ... digits. The reason for this is that you add a comma even for cases when "c" is zero length since you use the stop condition for your comma placement.

I attached your VI with a tiny correction; I put a comma only when "c" not equals zero.

Again, thanks for hosting DE!

/Mikael
Message 7 of 29
(9,263 Views)
Good job, Mikael...oftentimes minor problems with LabVIEW code aren't discovered until the code is actually used. 😉

Darren N.
0 Kudos
Message 8 of 29
(9,262 Views)
This solution works fine for an indicator, but is it possible to define such a format for numeric controls? Maybe with format string in the numeric properties? (in LabVIEW 7.1)

Thank you for your answer.
Michel
0 Kudos
Message 9 of 29
(9,018 Views)
Mikael,

It's still not good. For example it fails if there are 3 or more decimal digits.
0 Kudos
Message 10 of 29
(9,194 Views)