LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to Round Numbers in a String Array

Solved!
Go to solution

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.

0 Kudos
Message 1 of 5
(3,133 Views)

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.Smiley Wink

0 Kudos
Message 2 of 5
(3,127 Views)

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


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

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.

0 Kudos
Message 4 of 5
(3,046 Views)
Solution
Accepted by chivasmaniac12

@altenbach wrote:

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

 


Here's a simple version of that:

 

FormatTo2Decimals.png

Message 5 of 5
(3,040 Views)