xtd
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
parse_floating_point.cpp
Shows how to use format
xtd::parse
method with floating point values (float, double and decimal).
#include <xtd/xtd>
using namespace
xtd::globalization
;
auto
main() ->
int
{
culture_info::current_culture
(
culture_info
{
"en-US"
});
// change to us for currency
auto
d1 =
xtd::parse<double>
(
"12.345"
);
console::write_line
(d1);
auto
d2 =
xtd::parse<double>
(
"$12.345"
,
number_styles::currency
);
console::write_line
(d2);
auto
d3 =
xtd::parse<double>
(
"1.234500e+01"
,
number_styles::number
|
number_styles::allow_exponent
);
console::write_line
(d3);
auto
d4 =
xtd::parse<double>
(
"inf"
);
console::write_line
(d4);
auto
d5 =
xtd::parse<double>
(
"-inf"
);
console::write_line
(d5);
auto
d6 =
xtd::parse<double>
(
"nan"
);
console::write_line
(d6);
try
{
auto
d7 =
xtd::parse<double>
(
"Not floating point"
,
number_styles::any
);
console::write_line
(d7);
}
catch
(
const
system_exception
& e) {
console::write_line
(
"Exception : {}"
, e.message());
}
}
// This code produces the following output :
//
// 2.345
// 12.345
// 12.345
// inf
// -inf
// nan
// Exception : invalid character found
xtd::console::write_line
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
xtd::globalization::culture_info
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition
culture_info.hpp:42
xtd::globalization::culture_info::current_culture
static auto current_culture() noexcept -> xtd::globalization::culture_info
Gets the xtd::globalization::culture_info object that represents the culture used by the current appl...
xtd::system_exception
The exception that is thrown when a method call is invalid for the object's current state.
Definition
system_exception.hpp:18
xtd::parse< double >
auto parse< double >(const std::string &str, number_styles styles) -> double
Convert a string into a type.
Definition
parse.hpp:208
xtd::number_styles::any
@ any
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
Definition
number_styles.hpp:52
xtd::number_styles::currency
@ currency
Indicates that all styles except allow_exponent, allow_hex_specifier, allow_binary_specifier and allo...
Definition
number_styles.hpp:50
xtd::number_styles::allow_exponent
@ allow_exponent
Indicates that the numeric string can be in exponential notation. The allow_exponent flag allows the ...
Definition
number_styles.hpp:34
xtd::number_styles::number
@ number
Indicates that the allow_leading_white, allow_trailing_white, allow_leading_sign, allow_trailing_sign...
Definition
number_styles.hpp:46
xtd::globalization
Contains classes that define culture-related information, including language, country/region,...
Definition
culture_info.hpp:19
Generated on
for xtd by
Gammasoft
. All rights reserved.