DataFormatString: how to include padding zeros?


which (c#) dataformat string would you choose:

input: 1523.460
current output: 1523.46

Desired output: 1523.460
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

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.
Raab314159Author Commented:

The number is not allowed to have a fixed number of digits! Sometimes, the number may represent temperature, sometimes wavelenght, etc
All Courses

From novice to tech pro — start learning today.