diff --git a/src/pugixml.cpp b/src/pugixml.cpp index e487c85..20c32c5 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -6562,6 +6562,13 @@ namespace pugi return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision) : false; } + PUGI__FN bool xml_text::set(float rhs, int precision) + { + xml_node_struct* dn = _data_new(); + + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) : false; + } + PUGI__FN bool xml_text::set(double rhs) { xml_node_struct* dn = _data_new(); @@ -6569,6 +6576,13 @@ namespace pugi return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision) : false; } + PUGI__FN bool xml_text::set(double rhs, int precision) + { + xml_node_struct* dn = _data_new(); + + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) : false; + } + PUGI__FN bool xml_text::set(bool rhs) { xml_node_struct* dn = _data_new(); diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 6a79cae..f658109 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -772,7 +772,9 @@ namespace pugi bool set(long rhs); bool set(unsigned long rhs); bool set(double rhs); + bool set(double rhs, int precision); bool set(float rhs); + bool set(float rhs, int precision); bool set(bool rhs); #ifdef PUGIXML_HAS_LONG_LONG diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 0c4e564..ff9d440 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1773,10 +1773,17 @@ TEST(dom_fp_double_custom_precision) attr.set_value(1.0f, 5); CHECK(fp_equal(attr.as_double(), static_cast(1.0f))); + attr.set_value(3.1415926f, 3); CHECK(!fp_equal(attr.as_double(), static_cast(3.1415926f))); - node.text().set(std::numeric_limits::max()); + node.text().set(1.0f, 5); + CHECK(fp_equal(node.text().as_double(), static_cast(1.0f))); + + node.text().set(3.1415926f, 3); + CHECK(!fp_equal(node.text().as_double(), static_cast(3.1415926f))); + + node.text().set(std::numeric_limits::max(), 20); CHECK(fp_equal(node.text().as_double(), std::numeric_limits::max())); }