Skip to content

Commit a4e43c8

Browse files
committed
Update <format> example and docs
1 parent af65d64 commit a4e43c8

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

doc/modules/ROOT/pages/examples.adoc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,29 @@ This example can be found in the `examples/` folder as https://github.com/cppall
231231

232232
[source, c++]
233233
----
234-
#include <boost/decimal.hpp>
235-
#include <iostream>
236-
#include <format>
234+
include::example$format.cpp[]
235+
----
237236

238-
int main()
239-
{
240-
constexpr boost::decimal::decimal64_t val1 {314, -2};
241-
constexpr boost::decimal::decimal32_t val2 {3141, -3};
237+
Expected Output:
238+
----
239+
Default Format:
240+
3.14
241+
3.141
242242
243-
std::cout << std::format("{:10.3e}", val1) << '\n';
244-
std::cout << std::format("{:10.3e}", val2) << std::endl;
243+
Scientific Format:
244+
3.14e+00
245+
3.141e+00
245246
246-
return 0;
247-
}
247+
Scientific Format with Specified Precision:
248+
3.1e+00
249+
3.1e+00
250+
251+
Scientific Format with Specified Precision and Padding:
252+
03.140e+00
253+
03.141e+00
248254
----
249255

256+
250257
[#examples_print]
251258
== `<print>`
252259

examples/format.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// Copyright 2025 Matt Borland
22
// Distributed under the Boost Software License, Version 1.0.
33
// https://www.boost.org/LICENSE_1_0.txt
4+
//
5+
// This example demonstrates usage and formatting of decimal types with <format>
46

5-
#include <boost/decimal.hpp>
7+
#include <boost/decimal/decimal32_t.hpp> // For type decimal32_t
8+
#include <boost/decimal/decimal64_t.hpp> // For type decimal64_t
9+
#include <boost/decimal/format.hpp> // For <format> support (when available)
610
#include <iostream>
711

12+
// This macro is defined in boost/decimal/format.hpp if the platform has <format> support
813
#ifdef BOOST_DECIMAL_HAS_FORMAT_SUPPORT
914

1015
#include <format>

0 commit comments

Comments
 (0)