# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Unable to Round Numbers in a String Array

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.

Message 1 of 5
(3,348 Views)

## Re: Unable to Round Numbers in a String Array

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.

Message 2 of 5
(3,342 Views)

## Re: Unable to Round Numbers in a String Array

To round to a decimal place, multiply by 10^x, do the rounding to the nearest integer, then divide by 10^x.

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
Message 3 of 5
(3,310 Views)

## Re: Unable to Round Numbers in a String Array

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.

Message 4 of 5
(3,261 Views)
Solution
Accepted by topic author chivasmaniac12

## Re: Unable to Round Numbers in a String Array

@altenbach wrote:

(If you want to convert, just scan the string and then reformat it as "%.02f").

Here's a simple version of that:

Message 5 of 5
(3,255 Views)