Formatting currency within a specific precision range
Posted
by
Alex Prose
on Stack Overflow
See other posts from Stack Overflow
or by Alex Prose
Published on 2014-06-10T14:53:00Z
Indexed on
2014/06/10
15:24 UTC
Read the original article
Hit count: 145
c#
|string-formatting
I am trying to format currency that will always contain 2 decimal digits, but if there are extra digits of accuracy to display up to five. As an example:
for value = 5.0
display: $5.00
for value = 5.023
display: $5.023
for value = 5.333333333333333
display: $5.33333
I have been playing with the .ToString() formatting, but I can't seem to find the right match of options.
Clarification: I want to show from 2-5 decimals, truncating zeros after the second digit.
for value = 5.000000000000000
display: $5.00
for value = 5.333333333333333
display: $5.33333
© Stack Overflow or respective owner