Is there a setting to change doubles to decimals?
See original GitHub issueI am trying to generate a CSharp Client from a swagger URL online using the NSwagStudio.
Some of the definitions look like this:
"initialInvestment": {
"type": "number",
"format": "double",
"description": "The minimum initial investment required to purchase the fund"
},
It returns money as doubles, but I know I should be using decimals for money. Is there a setting in here somewhere to generate my POCOs using decimals any time it sees a type number with format double?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:25 (9 by maintainers)
Top Results From Across the Web
C# correct and efficient conversion of double to decimal
I really think your way is better. You can simply cast the double to decimal: double doubleValue = 12.23; decimal decimalValue = (decimal) ......
Read more >Java double decimal precision
How to set double precision to 2 decimal places? A double in Java is a 64-bit number, and the 64-bit precision of a...
Read more >Why not allow double/decimal implicit conversions?
The easy answer is: there cannot be an implicit conversion from double to decimal because of the range discrepancy; a huge number of...
Read more >Convert.ToDecimal Method (System)
Converts the value of the specified double-precision floating-point number to an equivalent decimal number. ToDecimal(Decimal).
Read more >When should you use Decimal instead of Double?
I'm currently working on a project that primarily deals with money calculations and money estimations. I started out using Double for the values ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Given that numbers are already converted to a decimal string format when serialising them as JSON across the wire, it would be preferable to have
decimal
as the default real number type in clients (or at the very least this should be easily configurable without custom code).That is, although the spec format name is “double”, in JSON or XML this necessarily means “decimal approximation of double”, so by converting on the client side back to
double
you’re only approximating an approximation. Having only one level of approximation, taking thedecimal
conversion, would be better. At the moment I’m using just decimals on the server side anyway (no approximation) and I’m having to add in a custom pre-processor in every NSwag client to avoid the imprecision.I am using stoplight studio to create the spec for a new API and if I edit the json to define a property as:
then NSwagStudio v13.16.1.0 generates:
unless you mean:
then NSwagStudio v13.16.1.0 generates: