09-21-2022 07:29 PM
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
Solved! Go to Solution.
09-21-2022 08:34 PM
@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.
09-22-2022 02:27 AM
09-22-2022 02:34 AM
Your Information is a bit ambiguous.
09-22-2022 09:31 AM
@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.
09-22-2022 09:37 AM
Note that you can use the format string of a numeric control:
09-22-2022 09:51 AM
@paul_cardinale wrote:
Note that you can use the format string of a numeric control:
If going that far, you should just use the Numeric Text.Text property.
09-22-2022 10:12 AM
@crossrulz wrote:
@paul_cardinale wrote:
Note that you can use the format string of a numeric control:
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.
09-22-2022 10:17 AM
@paul_cardinale wrote:
Note that you can use the format string of a numeric control:
This is gold.
09-22-2022 10:24 AM
@paul_cardinale wrote:
Note that you can use the format string of a numeric control:
That's clever, never thought of that!