Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show digits of Number, even when it is 0 (input:12 output:12.00)

Hey is there is simple way to show 12 as 12.00, when I convert it to string?
I can’t just add zeros, cause it also has inputs with digits, where only one 0 need to be added.

Some inputs and there espected outputs:


12    ->    12.00 
1.3   ->    1.30
0.2   ->    0.2
3.454 ->    3.45

I have tried this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

String.Format("{0:0.00}", Regex.Replace(VerkaufspreisInput.Text, 12);

Output 12

It’s the wrong function.

Thanks for help!

>Solution :

You can use ToString with N2, e.g.:

Console.WriteLine((12.00).ToString("N2"));

Will print 12.00.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading