The following causes an overflow error:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
var strValue = "10000.0000000000000000000000001"; Decimal128 decimal128Value; Decimal128.TryParse( strValue, out decimal128Value ); var decimalValue = Decimal128.ToDecimal( decimal128Value );
Not that converting to double does not overflow:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
var doubleValue = Decimal128.ToDouble( decimal128Value );
It is unclear why the Decimal128 value offers different precision than a standard .NET decimal. However the conversion to the .NET decimal should allow for a truncation of precision if necessary, as there currently is no other safe way to convert to decimal without going through some other type first (string or double).
- is duplicated by
-
CSHARP-2098 Decimal128.Compare() gives inaccurate results
- Closed