[#BloombergLP-bdljsn-NumberUtil]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdljsn.adoc[bdljsn]::NumberUtil
:relfileprefix: ../../
:mrdocs:

This `struct` provides a namespace for a suite of functions that convert between a JSON formated numeric value and various numerical types&period; The valid syntax for a JSON formatted numeric value is spelled out in `https&colon;&sol;&sol;www&period;rfc&hyphen;editor&period;org&sol;rfc&sol;rfc8259&num;section&hyphen;6`&period;

== Synopsis

Declared in `&lt;bdljsn&lowbar;numberutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
struct NumberUtil;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdljsn/NumberUtil/Int64.adoc[`Int64`] 
| This `typedef` is an alias to `bsls&colon;&colon;Types&colon;&colon;Int64`&period;
| xref:BloombergLP/bdljsn/NumberUtil/Uint64.adoc[`Uint64`] 
| This `typedef` is an alias to `bsls&colon;&colon;Types&colon;&colon;Uint64`&period;
|===


== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdljsn/NumberUtil/_04enum.adoc[`Unnamed enum`] 
| Special integer conversion status values&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdljsn/NumberUtil/areEqual.adoc[`areEqual`] 
| Return `true` if the specified `lhs` and `rhs` represent the same numeric value, and `false` otherwise&period; This function will return `true` for differing representations of the same number (e&period;g&period;, `1&period;0`, &quot;1&quot;, &quot;0&period;1e&plus;1&quot; are all equivalent) _except_ in cases where the exponent cannot be represented by a 64&hyphen;bit integer&period; If the exponent is outside the range of a 64&hyphen;bit integer, `true` will be returned if `lhs &equals;&equals; rhs`&period; For example, comparing &quot;1e18446744073709551615&quot; with itself will return `true`, but comparing it to &quot;10e18446744073709551614&quot; will return `false`&period; The behavior is undefined unless `isValidNumber(lhs)` and `isValidNumber(rhs)`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asDecimal64.adoc[`asDecimal64`] 
| Return the closest floating point representation to the specified `value`&period; If `value` is outside the representable range, return &plus;INF or &hyphen;INF (as appropriate)&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asDecimal64Exact.adoc[`asDecimal64Exact`] 
| Load the specified `result` with the specified `value`, even if a non&hyphen;zero status is returned&period; Return 0 if `value` can be represented exactly, and return `k&lowbar;INEXACT` and load `result` with the closest approximation of `value` if `value` cannot be represented exactly&period; A `value` can be represented exactly as a `Decimal64` if, for the significand and exponent of `value`, `abs(significand) &lt;&equals; 9,999,999,999,999,999` and `&hyphen;398 &lt;&equals; exponent &lt;&equals; 369`&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asDouble.adoc[`asDouble`] 
| Same as the related overload above for `asDouble`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asFloat.adoc[`asFloat`] 
| Return the closest floating point representation to the specified `value`&period; If `value` is outside the representable range, return &plus;INF or &hyphen;INF (as appropriate)&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asInt.adoc[`asInt`] 
| Same as the related overload above for `asInt`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asInt64.adoc[`asInt64`] 
| Same as the related overload above for `asInt64`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asInteger.adoc[`asInteger`] 
| Load into the specified `result` (of the template parameter type `t&lowbar;INTEGER&lowbar;TYPE`) with the specified `value`, even if a non&hyphen;zero status is returned (truncating fractional digits if necessary)&period; Return 0 on success, `k&lowbar;OVERFLOW` if `value` is larger than can be represented by `result`, `k&lowbar;UNDERFLOW` if `value` is smaller than can be represented by `result`, and `k&lowbar;NOT&lowbar;INTEGRAL` if `value` is not an integral number (i&period;e&period;, there is a fractional part)&period; For underflow, `result` will be loaded with the minimum representable value, for overflow, `result` will be loaded with the maximum representable value, for non&hyphen;integral values `result` will be loaded with the integer part of `value` (truncating the value to the nearest integer)&period; If the result is not an integer and also either overflows or underflows, it is treated as an overflow or underflow (respectively)&period; The (template parameter) `t&lowbar;INTEGER&lowbar;TYPE` shall be either a signed or unsigned integer type (that is not `bool`) where `sizeof(t&lowbar;INTEGER&lowbar;TYPE) &lt;&equals; 8`&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period; Note that this operation will correctly handle exponents (e&period;g&period;, a `value` of &quot;0&period;00000000000000000001e20&quot; will produce a `result` of 1)&period;
| xref:BloombergLP/bdljsn/NumberUtil/asLong.adoc[`asLong`] 
| Same as the related overload above for `asLong`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asLonglong.adoc[`asLonglong`] 
| Same as the related overload above for `asLonglong`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asShort.adoc[`asShort`] 
| Load the specified `result` with the specified `value`, even if a non&hyphen;zero status is returned (truncating fractional digits if necessary)&period; Return 0 on success, `k&lowbar;OVERFLOW` if `value` is larger than can be represented by `result`, `k&lowbar;UNDERFLOW` if `value` is smaller than can be represented by `result`, and `k&lowbar;NOT&lowbar;INTEGRAL` if `value` is not an integral number (i&period;e&period;, there is a fractional part)&period; For underflow, `result` will be loaded with the minimum representable value, for overflow, `result` will be loaded with the maximum representable value, for non&hyphen;integral values `result` will be loaded with the integer part of `value` (truncating the fractional part of `value`)&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period; Note that this operation will correctly handle exponents (e&period;g&period;, a `value` of &quot;0&period;00000000000000000001e20&quot; will produce a `result` of 1)&period;
| xref:BloombergLP/bdljsn/NumberUtil/asUint.adoc[`asUint`] 
| Same as the related overload above for `asUint`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asUint64.adoc[`asUint64`] 
| Same as the related overload above for `asUint64`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asUlong.adoc[`asUlong`] 
| Load the specified `result` with the specified `value`, even if a non&hyphen;zero status is returned (truncating fractional digits if necessary)&period; Return 0 on success, `k&lowbar;OVERFLOW` if `value` is larger than can be represented by `result`, `k&lowbar;UNDERFLOW` if `value` is smaller than can be represented by `result`, and `k&lowbar;NOT&lowbar;INTEGRAL` if `value` is not an integral number (i&period;e&period;, there is a fractional part)&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asUlonglong.adoc[`asUlonglong`] 
| Same as the related overload above for `asUlonglong`&period;
| xref:BloombergLP/bdljsn/NumberUtil/asUshort.adoc[`asUshort`] 
| Same as the related overload above for `asUshort`&period;
| xref:BloombergLP/bdljsn/NumberUtil/isIntegralNumber.adoc[`isIntegralNumber`] 
| Return `true` if the specified `value` is a valid integral JSON number&period; Note that this function may return `true` even if `value` cannot be represented in a fundamental integral type&period; The behavior is undefined unless `isValidNumber(value)` is `true`&period;
| xref:BloombergLP/bdljsn/NumberUtil/isValidNumber.adoc[`isValidNumber`] 
| Return `true` if the specified `value` is a valid JSON number&period; Note that this function may return `true` even if `value` cannot be represented in any particular number type&period;
| xref:BloombergLP/bdljsn/NumberUtil/stringify-0c.adoc[`stringify`] 
| `stringify` overloads
|===



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