06-03-2009 06:20 PM
Hi.
I am trying to do something that seems quite simply, and I am surprised at how much trouble I am having with this. I am pretty sure that there is a way to get LabVIEW to do this.
I have an array of numbers (double), and I am using the "Array To Spreadsheet String" function to generate a string that I can write to a file.
The problem I am having is that I want to string to omit unnecessary trailing zeros after the decimal point, but I don't want to limit the precision of numbers that do require it.
For example, if my data is this:
0.02
0.4476
-0.0244570001
I would like for the string that I get to be exactly like what I wrote above. However, depeding on the format string I use, this is what I get:
format string: %.10f
0.0200000000
0.4476000000
-0.0244570001
<OR>
format string: %f (this seems to default to 6 digits)
0.020000
0.447600
-0.024457
<OR>
format string: %.4f
0.0200
0.4476
-0.0244 <= all trailing digits for this number have been lost!!
Does someone know what the format string should be to get the string I want (which is this:)
0.02
0.4476
-0.0244570001
Thanks in advance,
Alejandro
Solved! Go to Solution.
06-03-2009 06:39 PM
Hello Alejandro:
Try %#f
06-04-2009 12:05 AM
AlejandroZepeda wrote:Hi.
I am trying to do something that seems quite simply,
For example, if my data is this:
0.02
0.4476
-0.0244570001
I would like for the string that I get to be exactly like what I wrote above. However, depeding on the format string I use, this is what I get:
format string: %.10f
0.0200000000
0.4476000000
-0.0244570001
Does someone know what the format string should be to get the string I want (which is this:)
0.02
0.4476
-0.0244570001
Thanks in advance,
Alejandro
Hi Alejandro,
remember that if you used a %20f formatter you most likely would see a digit appearing in the .4476 value. Your computer is binary, but your display is decimal, there allways will be rounding errors.
Ton
06-04-2009 09:05 AM
Hello.
Thanks for your responses.
I tried using %#f, but I got the same result as %f.
Then I tried %#.10f, and that worked exactly as I wanted it to.
Thanks a lot for the tip, DonPogi!
Alejandro