-2

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:

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

Output 12

It's the wrong function.

Thanks for help!

Jonas
  • 1
  • 2

2 Answers2

1

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

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

Will print 12.00.

rotgers
  • 1,992
  • 1
  • 15
  • 25
0

I think you're close, but you need to change the second part of your String.Format (the format specifier).

Try changing {0:0.00} to {0:F2}

For reference, here is the documentation for format specifiers for numbers: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings