docs: "hello units" example updated with dimensions output

This commit is contained in:
Mateusz Pusz
2024-02-26 14:36:49 +01:00
parent aa72c830c4
commit d9723b61a6
3 changed files with 15 additions and 15 deletions

View File

@ -120,11 +120,11 @@ int main()
std::cout << v1 << '\n'; // 110 km/h std::cout << v1 << '\n'; // 110 km/h
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
std::cout << std::format("{:*^10}\n", v3); // *110 km/h* std::cout << std::format("{:*^10}\n", v3); // *110 km/h*
std::println("{:%N in %U}", v4); // 70 in mi/h std::println("{:%N in %U of %D}", v4); // 70 in mi/h of LT⁻¹
std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s
std::println("{:{%N:.2f}%?{%U:n}}", v6); // 31.29 m s⁻¹ std::println("{:{%N:.2f}%?{%U:dn}}", v6); // 31.29 ms⁻¹
std::println("{:%N}", v7); // 31 std::println("{:%N}", v7); // 31
} }
``` ```
_Try it on the [Compiler Explorer](https://godbolt.org/z/hWzxf1j1M)._ _Try it on the [Compiler Explorer](https://godbolt.org/z/n8GEdfeed)._

View File

@ -99,9 +99,9 @@ performed without sacrificing accuracy. Please see the below example for a quick
std::cout << v1 << '\n'; // 110 km/h std::cout << v1 << '\n'; // 110 km/h
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
std::cout << std::format("{:*^10}\n", v3); // *110 km/h* std::cout << std::format("{:*^10}\n", v3); // *110 km/h*
std::println("{:%N in %U}", v4); // 70 in mi/h std::println("{:%N in %U of %D}", v4); // 70 in mi/h of LT⁻¹
std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s
std::println("{:{%N:.2f}%?{%U:n}}", v6); // 31.29 m s⁻¹ std::println("{:{%N:.2f}%?{%U:dn}}", v6); // 31.29 ms⁻¹
std::println("{:%N}", v7); // 31 std::println("{:%N}", v7); // 31
} }
``` ```
@ -143,14 +143,14 @@ performed without sacrificing accuracy. Please see the below example for a quick
std::cout << v1 << '\n'; // 110 km/h std::cout << v1 << '\n'; // 110 km/h
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
std::cout << std::format("{:*^10}\n", v3); // *110 km/h* std::cout << std::format("{:*^10}\n", v3); // *110 km/h*
std::println("{:%N in %U}", v4); // 70 in mi/h std::println("{:%N in %U of %D}", v4); // 70 in mi/h of LT⁻¹
std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s
std::println("{:{%N:.2f}%?{%U:n}}", v6); // 31.29 m s⁻¹ std::println("{:{%N:.2f}%?{%U:dn}}", v6); // 31.29 ms⁻¹
std::println("{:%N}", v7); // 31 std::println("{:%N}", v7); // 31
} }
``` ```
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/hWzxf1j1M)" !!! example "[Try it on Compiler Explorer](https://godbolt.org/z/n8GEdfeed)"
!!! note !!! note

View File

@ -58,11 +58,11 @@ int main()
constexpr quantity v6 = value_cast<m / s>(v4); constexpr quantity v6 = value_cast<m / s>(v4);
constexpr quantity v7 = value_cast<int>(v6); constexpr quantity v7 = value_cast<int>(v6);
std::cout << v1 << '\n'; // 110 km/h std::cout << v1 << '\n'; // 110 km/h
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
std::cout << MP_UNITS_STD_FMT::format("{:*^10}\n", v3); // *110 km/h* std::cout << MP_UNITS_STD_FMT::format("{:*^10}\n", v3); // *110 km/h*
std::cout << MP_UNITS_STD_FMT::format("{:%N in %U}\n", v4); // 70 in mi/h std::cout << MP_UNITS_STD_FMT::format("{:%N in %U of %D}\n", v4); // 70 in mi/h of LT⁻¹
std::cout << MP_UNITS_STD_FMT::format("{:{%N:.2f}%?%U}\n", v5); // 30.56 in m/s std::cout << MP_UNITS_STD_FMT::format("{:{%N:.2f}%?%U}\n", v5); // 30.56 in m/s
std::cout << MP_UNITS_STD_FMT::format("{:{%N:.2f}%?{%U:n}}\n", v6); // 31.29 in m s⁻¹ std::cout << MP_UNITS_STD_FMT::format("{:{%N:.2f}%?{%U:dn}}\n", v6); // 31.29 in ms⁻¹
std::cout << MP_UNITS_STD_FMT::format("{:%N}\n", v7); // 31 std::cout << MP_UNITS_STD_FMT::format("{:%N}\n", v7); // 31
} }