07-14-2017 03:36 PM
Hello,
I have am having an issue with taking an array of strings and rounding those string numbers within the array to two decimal places. I was able to round to the nearest integer by converting the array of strings to an array of numbers then rounding and converting back(its ok if i loose the text strings), but I have been unable to specify I want two decimal points for a whole array.
Solved! Go to Solution.
07-14-2017 03:40 PM
Okay.
So if you'd like some help solving that problem, you can help us by actually attaching the VI you have created that is giving you problems. Include some data as default and tell us what it is actually doing and what you expect the results to be.
We can't help you solve a problem if you haven't actually shown us the problem.
07-14-2017 06:42 PM
To round to a decimal place, multiply by 10^x, do the rounding to the nearest integer, then divide by 10^x.
07-15-2017 09:52 AM - edited 07-15-2017 10:13 AM
If you already have fractional numbers as decimal strings, all you need to do is find the relevant decimal delimiters and truncated after two more digits. There is no need to do an expensive conversion to a numeric data type. (If you want to convert, just scan the string and then reformat it as "%.02f").
How do the strings look like? How are they arranged? Is there also plain text before or after the numbers? (you mentioned "... its ok if i loose the text strings"). Do some numbers contain fewer than 2 decimal digits and do you want to pad those with zeroes or leave them alone? Are there other formats (SI units, scientific E format, etc.)?
I assume you are aware that "# of decimal digits" applies only to formatted strings and is only a cosmetic property for numeric datatypes.
07-15-2017 10:05 AM - edited 07-15-2017 10:08 AM
@altenbach wrote:
(If you want to convert, just scan the string and then reformat it as "%.02f").
Here's a simple version of that: