Search code examples
c#string

Im trying to make decimal only have two digits after the period, how would i do that?


Im trying to make a decimal only have two spots. For example: i would try and make 1.2345 = 1.23.

I tried 'String.Format("{0.0.00}", cats.ToString());' but it gave me an error, basically saying it wasn't in a correct format.


Solution

  • In c# you can try

    Math.Round(1.2345, 2);

    or

    string.Format("{0:0.00}", 1.2345) you can use this with string Interpolation $"{1.2345: 0.00}"