I want to analyze the value doublein string. I want my number to have a certain number of digits (which I won’t know until done). If this number can be expressed with a non-zero value in the number of digits, this is what I want. If the number is zero, I want it to be expressed in scientific notation.
Some examples will make this more clear, this suggests that I wanted 3 digits:
Value: .2367 Output: "0.23"
Value: .00367 Output: "3.67E-3"
Value: 22.3 Output: "22.3"
Value: 3364.0 Output: "3.36E3"
In my work around the solution, the ToString () method and the N number format will be used , and if this leads to a zero return to the format string E, but this is like reusing the wheel. Does anyone know if there is a built-in method for this?
source
share