LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Quick question on converting number to string

Solved!
Go to solution

Hello, 

 

I have a basic question to which I couldn't find a proper solution after searching the web. that I came across while developing a serial communication program. When I convert a number to string format, how do I preserve the leading zeros of the number? For example, the user enters 0025 in numerical control, I want to convert this to a string as "0025" but after conversion, it always returns as "25" 

 

Thank you 

 

0 Kudos
Message 1 of 11
(437 Views)

@ATX1122 wrote:

Hello, 

 

I have a basic question to which I couldn't find a proper solution after searching the web. that I came across while developing a serial communication program. When I convert a number to string format, how do I preserve the leading zeros of the number? For example, the user enters 0025 in numerical control, I want to convert this to a string as "0025" but after conversion, it always returns as "25" 

 

Thank you 

 


"Format Into String" is what you are looking for.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 11
(422 Views)

Hi ATX,

 

read the help for FormatIntoString, especially the paragraph on format codes.

 

Then you should know what "%04d" means…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO
Message 3 of 11
(395 Views)

Your Information is a bit ambiguous.

  • Is this a fixed format and you expect the user to input 4 digits?
  • What should happen if the user inputs 25 without leading zeroes?
  • What is the expected range of numbers?

 

Greets, Dave
0 Kudos
Message 4 of 11
(391 Views)

@ATX1122 wrote:

Hello, 

 

I have a basic question to which I couldn't find a proper solution after searching the web. that I came across while developing a serial communication program. When I convert a number to string format, how do I preserve the leading zeros of the number? For example, the user enters 0025 in numerical control, I want to convert this to a string as "0025" but after conversion, it always returns as "25" 

 

Thank you 

 


You can't "preserve the leading zeros" of a floating point number because there are none (the numbers are normalized and the MSB is 1).

However when converting a number to a string, you can choose a width and, if you use "Format Into String", you can choose to have leading zeros.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 11
(370 Views)
Solution
Accepted by crossrulz

Note that you can use the format string of a numeric control:

fn.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 6 of 11
(365 Views)

@paul_cardinale wrote:

Note that you can use the format string of a numeric control:

fn.png


If going that far, you should just use the Numeric Text.Text property.


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 7 of 11
(359 Views)

@crossrulz wrote:

@paul_cardinale wrote:

Note that you can use the format string of a numeric control:

fn.png


If going that far, you should just use the Numeric Text.Text property.


Sure, if you're going to use the value in the control.

However you could have some other value wired in.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 8 of 11
(354 Views)

@paul_cardinale wrote:

Note that you can use the format string of a numeric control:

fn.png


This is gold.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 11
(351 Views)

@paul_cardinale wrote:

Note that you can use the format string of a numeric control:

fn.png


That's clever, never thought of that!

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 10 of 11
(348 Views)