userver: userver/chaotic/io/userver/decimal64/decimal.hpp Source File
Loading...
Searching...
No Matches
decimal.hpp
1#pragma once
2
3#include <userver/chaotic/convert.hpp>
4#include <userver/decimal64/decimal64.hpp>
5
6USERVER_NAMESPACE_BEGIN
7
8namespace chaotic::convert {
9
10template <int Prec, typename RoundPolicy>
11std::string Convert(const decimal64::Decimal<Prec, RoundPolicy>& value, chaotic::convert::To<std::string>) {
12 return ToString(value);
13}
14
15template <int Prec, typename RoundPolicy>
16decimal64::Decimal<Prec, RoundPolicy>
17Convert(const std::string& str, chaotic::convert::To<decimal64::Decimal<Prec, RoundPolicy>>) {
18 return decimal64::Decimal<Prec, RoundPolicy>(str);
19}
20
21template <int Prec, typename RoundPolicy>
22decimal64::Decimal<Prec, RoundPolicy>
23Convert(const int& str, chaotic::convert::To<decimal64::Decimal<Prec, RoundPolicy>>) {
24 return decimal64::Decimal<Prec, RoundPolicy>(str);
25}
26
27template <int Prec, typename RoundPolicy>
28int Convert(const decimal64::Decimal<Prec, RoundPolicy>& value, chaotic::convert::To<int>) {
29 return value.ToInteger();
30}
31
32} // namespace chaotic::convert
33
34USERVER_NAMESPACE_END