0

I have a web API method that returns decimal value 52.00, when I debug the web API the value is coming correctly but when it returns the result in postman it is becoming only 52 but it should come as 52.00 and if the decimal is more than two then round it to .00

Here the result when I debug

enter image description here

Here the result in postman

enter image description here

C.Das
  • 87
  • 2
  • 12
  • 2
    Does this answer your question? [How can I force a minimum number of decimal places in Json.net?](https://stackoverflow.com/questions/34568963/how-can-i-force-a-minimum-number-of-decimal-places-in-json-net) – Martheen Dec 30 '20 at 07:58

2 Answers2

0

52, 52.0, 52.00, or 52.000 are the same value.
What you want seems to be format a decimal, float, double, or int to 2 decimal.
Like Leave only two decimal places after the dot.

You can check the Msdn reference guide on Numerical string format if you need more specific format. https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

But the question is still ambigiuous: What is the expected result when the precision is more than 2 decimal ? Do you want to trim or to round the value?

I will not apply those format to the Json, as you may loose precision, but only format the display.

Self
  • 349
  • 1
  • 8
0
  1. if you propertied data type is string then you can use

String.Format("{0:0.00}", 52.00);

decimalVar.ToString("F"); 23.456 → 23.46

  1. if properties is decimal it self with round of

Decimal.Round(52.167, 2)

52.167 → 52.17

This might help.

Kd Nimavat
  • 282
  • 1
  • 11