Skip to content

Commit cccf67b

Browse files
committed
Add conversion example to docs
1 parent d844e8d commit cccf67b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

doc/decimal/conversions.adoc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,34 @@ constexpr T from_dpd(unsigned __int128 bits) noexcept;
112112
} // namespace decimal
113113
} // namespace boost
114114
----
115+
116+
Example
117+
[source, c++]
118+
----
119+
#include <boost/decimal.hpp>
120+
#include <iostream>
121+
#include <iomanip>
122+
123+
using namespace boost::decimal;
124+
125+
int main()
126+
{
127+
const decimal32_fast fast_type {5};
128+
const std::uint32_t BID_bits {to_bid(fast_type)};
129+
const std::uint32_t DPD_bits {to_dpd(fast_type)};
130+
131+
std::cout << std::hex
132+
<< "BID format: " << BID_bits << '\n'
133+
<< "DPD format: " << DPD_bits << std::endl;
134+
135+
const decimal32 bid_decimal {from_bid<decimal32>(BID_bits)};
136+
const decimal32 dpd_decimal {from_dpd<decimal32>(DPD_bits)};
137+
138+
return !(bid_decimal == dpd_decimal);
139+
}
140+
----
141+
Output:
142+
----
143+
BID format: 31fc4b40
144+
DPD format: 35f00000
145+
----

0 commit comments

Comments
 (0)