To display a currency we do:
ToString("0.##")
For value 5.00
the output is:
5
For value 5.98
the output is:
5.98
For value 5.90
the output is:
5.9
I need the third case to come out with 2 decimal points, eg:
5.90
How can I do this without it affecting the other results?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
C is a function driven language because C is a procedural programming language. C++ is an object driven language because it is an object oriented programming. Function and operator overloading is not supported in C. Function and operator overloading is supported by C++. C is a function-driven language.
Try:
value.ToString("#,##0.00")
Or just:
value.ToString("C")
I know of no built-in way to expand out all two decimal places only when both are not zero. Would probably just use an if
statement for that.
if (s.EndsWith(".00")) s = s.Substring(0, s.Length - 3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With