DataFormatString: how to include padding zeros?

Hi,

which (c#) dataformat string would you choose:

input: 1523.460
current output: 1523.46

Desired output: 1523.460
Raab314159Asked:
Who is Participating?
 
ptmcompConnect With a Mentor Commented:
If you want the input to be equal to the output use string or save the number of significant digits in a seperate variable.

To format a number with 3 digits after decimal point use: string.Format("{0:#.000}", 1523.46)

In a float / double / decimal there is no information about the number of significant digits. You have to implement it yourself or you might find a 3rd party library which provides this functionality.
0
 
Raab314159Author Commented:
REM:

The number is not allowed to have a fixed number of digits! Sometimes, the number may represent temperature, sometimes wavelenght, etc
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.