[#BloombergLP-bdldfp-DecimalConvertUtil-decimal128FromFloat]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdldfp.adoc[bdldfp]::xref:BloombergLP/bdldfp/DecimalConvertUtil.adoc[DecimalConvertUtil]::decimal128FromFloat
:relfileprefix: ../../../
:mrdocs:

Return a decimal floating&hyphen;point number converted from `binary`&period;

== Synopsis

Declared in `&lt;bdldfp&lowbar;decimalconvertutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
xref:BloombergLP/bdldfp/Decimal128.adoc[Decimal128]
decimal128FromFloat(
    float binary,
    int digits = 0);
----

== Description

If `binary` is singular (&plus;&sol;&hyphen;NaN, &plus;&sol;&hyphen;Inf, or &plus;&sol;&hyphen;0) or is not within the representable range of the return type, return a corresponding decimal singular value&period;

Optionally specify `digits` to indicate the number of significant digits to produce in the returned value&period; The `digits` parameter is treated as follows&colon;

If `digits` is larger than the number of digits in the destination type, it will be reduced to that number of digits&period;

If `digits` is positive, the result is `binary` rounded to that many significant digits&period;

If `digits` is negative, the decimal value with the fewest significant digits that converts back to `binary` is returned if possible, and otherwise the value closest to `binary` is returned&period; Note that this provides the most visually appealing result but is the most expensive to compute&period;

If `digits` is not specified or 0, a default value will be used (possibly depending on the value of `binary`) based on the premise that `binary` is a converted decimal value of no more significant digits than is guaranteed to have a uniquely converted binary value (15 for `double`, 6 for `float` in general, and 7 for `float` in the range `&lsqb; &period;0009999995 &period;&period; 8589972000 &rsqb;`)&period; Note that this is likely to have the best performance for &quot;business&quot; numbers (i&period;e&period;, numbers that originate as decimal values in external market quote feeds)&period;

Note that the purpose of these functions is to restore a decimal value that has been converted to a binary floating&hyphen;point type&period; It is more efficient to use conversion constructors when all that is needed is the nearest decimal to the `binary` value&period;

Note that if `binary` is a `float` value that was converted from an IBM&sol;Perkin&hyphen;Elmer&sol;Interdata binary `float` value itself converted from a decimal value of no more than 6 significant digits, specifying 6 for `digits` will recover the original decimal value&period; Not specifying `digits` may result in a value having a spurious seventh digit&period;

== Return Value

decimal value restored from `binary`

== Parameters

[cols="1,4"]
|===
| Name| Description
| *binary*
| binary floating&hyphen;point value to convert
| *digits*
| optional significant digit count&semi; see above
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
