An extra .0 when returning JSON response that contains decimal type
Sometimes when we are designing API responses, we might want to return a JSON string which contains decimal-type field. We could easily represent the decimal-type field with string, so the response is in the following format: { "amount": "3.00" } However, for whatever reason, if you want to return the amount field in decimal, and let's say it is very important the number of decimal place is shown correctly, there is some configuration required to get that right, as without any intervention, the client will end up seeing something as follow. *I am writing this based on the API designed using .NET's tech. stack. { "amount": 3.0 } Assuming we want the amount to be returned in 2 decimal places, 3.00, we could achieve that with the use of attribute. Let's start by creating a class with a property called amount . public class Receipt { public decimal amount { get; set; } } At some point, we want to serialize the above...