Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove trailing zeros using EngineeringFormatInfo?

HI,

 

I found a measurement studio formatter for SI notation.  

For details, see the NI document.

 

Here, I want to know how to remove any trailing zeros. I could not find any information about this. 

 

For example, 

 

code : string result = string.Format(EngineeringFormatInfo.Default, {0:s5}, double value)

 

if  value = 1.2345678E-3,  result is 1.23457E-3. It is ok. 

if  value = 1.2E-3,  result is 1.20000E-3. But I want to get "1.23m". 

 

In labview, I usually use "%#.5p" format string.

0 Kudos
Message 1 of 7
(5,761 Views)

@diluculo wrote:

HI,

 

I found a measurement studio formatter for SI notation.  

For details, see the NI document.

 

Here, I want to know how to remove any trailing zeros. I could not find any information about this. 

 

For example, 

 

code : string result = string.Format(EngineeringFormatInfo.Default, {0:s5}, double value)

 

if  value = 1.2345678E-3,  result is 1.23457E-3. It is ok. 

if  value = 1.2E-3,  result is 1.20000E-3. But I want to get "1.23m". 

 

In labview, I usually use "%#.5p" format string.


I don't understand how you are getting 1.23457E-3 ?  And claiming that is okay.

If you are using the format string that you claim you are using, then you should be getting 1.23457m.

 

It sounds like you are using string result = string.Format(EngineeringFormatInfo.Default, {0:E5}, value)

 

 

 

0 Kudos
Message 2 of 7
(5,757 Views)
You are right. i mistyped.

Anyway, my question is "Is there any way to remove zeroes in using EngineeringFormatInfo?"

0 Kudos
Message 3 of 7
(5,753 Views)

code : string result = string.Format(EngineeringFormatInfo.Default, {0:s5}, value)

value = 1.2345678E-3 -> result = "1.23457m"
value = 1.23E-3 -> result = "1.23000m". But I want to get "1.23m" without trailing zeros.
0 Kudos
Message 4 of 7
(5,752 Views)

@diluculo wrote:

code : string result = string.Format(EngineeringFormatInfo.Default, {0:s5}, value)

value = 1.2345678E-3 -> result = "1.23457m"
value = 1.23E-3 -> result = "1.23000m". But I want to get "1.23m" without trailing zeros.

Based on the documentation page you linked, the answer is no.

0 Kudos
Message 5 of 7
(5,750 Views)

So, unfortunately, there is no native way to format numbers in metric units even in the Measurement Studio. 

 

Thanks.

 

 

 

0 Kudos
Message 6 of 7
(5,746 Views)

I believe the formatter is working as expected, treating the value as containing five significant digits after the decimal (including trailing zeros). Using scientific notation, the value 1.23000 indicates a more precise value than 1.23 with the trailing significant digits removed.


Unfortunately, I do not know of any existing format mode that supports a "maximum digit count" (they either show all digits, or an "absolute digit count").

~ Paul H
0 Kudos
Message 7 of 7
(5,716 Views)