N
nvx
Hi,
I'm looking for a simple way to convert a Double to a String exactly
the .ToString() does, except these two differences:
- the number of decimals is given (rounding is applied if
necessary), and
- trailing zeroes are kept.
This means I need it to be converted using the scientific notation if
the number is greater than a certain value etc., not just a simple
"this number of digits (or more if needed) before the decimal point
and precisely this number of decimals after the decimal point."
I could round the Double before converting it to a String
using .ToString(), but the trailing zeroes would be omitted.
Similarly, I could use the format string "0.00" or "0.00E+00", but the
scientific notation would not or would be used respectively (i.e.
converting 100.567 to "100.57" (which is OK) / "1.00E+02" (which means
a significant loss of data) and converting 123456789123456789.12345 to
"123456789123456789.12" (awful...) / 1.23E+15 (this is the correct
conversion now)).
So, do I need to create an appropriate format string according to the
current Double value or is there some elegant solution of this?
Thanks for any help...
With regards
nvx
I'm looking for a simple way to convert a Double to a String exactly
the .ToString() does, except these two differences:
- the number of decimals is given (rounding is applied if
necessary), and
- trailing zeroes are kept.
This means I need it to be converted using the scientific notation if
the number is greater than a certain value etc., not just a simple
"this number of digits (or more if needed) before the decimal point
and precisely this number of decimals after the decimal point."
I could round the Double before converting it to a String
using .ToString(), but the trailing zeroes would be omitted.
Similarly, I could use the format string "0.00" or "0.00E+00", but the
scientific notation would not or would be used respectively (i.e.
converting 100.567 to "100.57" (which is OK) / "1.00E+02" (which means
a significant loss of data) and converting 123456789123456789.12345 to
"123456789123456789.12" (awful...) / 1.23E+15 (this is the correct
conversion now)).
So, do I need to create an appropriate format string according to the
current Double value or is there some elegant solution of this?
Thanks for any help...
With regards
nvx