Skip to content

Modern Finance DecimalFromDouble

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Finance › Finance › DecimalFromDouble

DecimalFromDouble

Converts a double to a Decimal of 15 significant digits; NaN or infinity gives Invalid.

Syntax

DecimalFromDouble( d )

Examples

#import "std/money"
using money

'' NAMED, because it is not exact -- the DOUBLE 0.1 is not one tenth.
'' Fifteen significant digits, trailing zeros stripped, which is what
'' .NET's double -> decimal conversion does
print DecimalFromDouble( 0.1 ).ToString( )       '' 0.1
print DecimalFromDouble( 1.0 / 3.0 ).ToString( ) '' 0.333333333333333

'' Storing all seventeen digits would store the ERROR rather than the
'' number: the DOUBLE 0.1 is really
'' 0.1000000000000000055511151231257827

'' NaN and the infinities have no decimal value
print DecimalFromDouble( 0.0 / 0.0 ).IsValid( )  '' false
print DecimalFromDouble( 1.0e300 ).IsValid( )    '' false

Library: Finance
Category: Finance
Documented under: Nothing Becomes A Keyword

Clone this wiki locally