08-22-2012 12:29 AM
Solved! Go to Solution.
08-22-2012 12:57 AM - edited 08-22-2012 12:59 AM
Hi
did you try "%#_6g"? where the 6 is the significant digits. you can change it to your need.
try this "%#.6g" if you want 6 digits of precision.
how are you trrying to set the format? using a property node? if you want to do it manually on a control object, you can set it in the properties dialog box of the control.
08-22-2012 07:46 AM - edited 08-22-2012 07:47 AM
Check out this website:
08-22-2012 08:48 AM
Z.K. wrote:
[...] or some other way.
I tried and I tried but I couldn't crack it with one regular expression, so I took the easy way out. The first Match Pattern finds the decimal point and the second one clears trailing zeros from the rest. It doesn't discriminate between numbers and everything else, though.
08-22-2012 09:17 AM - edited 08-22-2012 09:21 AM
@jcarmody wrote:
@Z.K. wrote:
[...] or some other way.
I tried and I tried but I couldn't crack it with one regular expression, so I took the easy way out. The first Match Pattern finds the decimal point and the second one clears trailing zeros from the rest. It doesn't discriminate between numbers and everything else, though.
Well, if Jim can't crack it with a regex, abandon all hope ye who entereth here.
Im more of the opinion that a Scan from string to DBL + formating the indicator's display is the better approach though.
08-22-2012 09:57 AM
Jim,
I checked it and it actually works with just one regular expression, 0*$ or 0+$. Before substring is the number without trailing zeros.
08-22-2012 10:25 AM
@Sergey Kolbunov wrote:
Jim,
I checked it and it actually works with just one regular expression, 0*$ or 0+$. Before substring is the number without trailing zeros.
If you can GUARANTEE that a decimal point is in the input string it would work, but try it with an input string of "1000" (without the quotes)
Rod.
08-22-2012 11:31 AM
@Jeff Bohrer wrote:
[...]
Well, if Jim can't crack it with a regex, abandon all hope ye who entereth here.
[...]
Darin.K hasn't chimed in. His opinion is a much better guide as to whether it's solveable or not.
08-22-2012 12:05 PM - edited 08-22-2012 12:09 PM
Well, since you asked my quick answer is to not look at which parts to grab from the string, but rather which parts to eliminate. I would go with a Search & Replace:
My usual taste is to leave at least one zero after the radix point (ie. 1000.00000 becomes 1000.0), so what I show here uses a minimum width. The example as written gives a minimum width of three digits after the radix point (if the original number has more than three). You can change the number 3 to be any minimum width you like, or remove the quantifier for a min width of 1. (\d{1,3}+ becomes \d).
Edit: Added bonus, as you see it will do the deed to multiple numbers in a string without a loop.
Edit 2: Would I really do this using a Regex, maybe not, but the point here is that it could be done.
08-22-2012 01:14 PM - edited 08-22-2012 01:20 PM
@jcarmody wrote:
@Jeff Bohrer wrote:
[...]
Well, if Jim can't crack it with a regex, abandon all hope ye who entereth here.
[...]
Darin.K hasn't chimed in. His opinion is a much better guide as to whether it's solveable or not.
Now that Dr K has chimed in... (and solved it without a regex) I'll stand by my statement of "abandon all hope". some other method may work. a Regex will not be the best solution in this case.