Skip to content

Conversation

@romainreignier
Copy link

For example the number 1.0 will be converted to "1.0" instead of "1".
This allows to keep the correct type information when parsing back the YAML.

This is an attempt to Fix #226 #412 #1016

…ith only integral part

For example the number 1.0 will be converted to "1.0" instead of "1".
This allows to keep the correct type information when parsing back the YAML.

Fix jbeder#226 jbeder#412 jbeder#1016
romainreignier added a commit to romainreignier/yaml-cpp that referenced this pull request Oct 16, 2025
…ith only integral part

For example the number 1.0 will be converted to "1.0" instead of "1".
This allows to keep the correct type information when parsing back the YAML.

This patch is equivalent of jbeder#1377 but for the 0.8.0 version of yaml-cpp.
@romainreignier
Copy link
Author

I don't know if it worth adding it, but this test fail on master and pass with this patch:

void testRoundTripDouble(double value) {
    Emitter out;
    out << value;
    Node node = Load(out.c_str());
	int64_t intValue;
	EXPECT_FALSE(YAML::convert<int64_t>::decode(node, intValue));
	double doubleValue;
	EXPECT_TRUE(YAML::convert<double>::decode(node, doubleValue));
    EXPECT_EQ(doubleValue, value);
}

TEST(RoundTripTest, Double) {
    testRoundTripDouble(0.0);
    testRoundTripDouble(3.14159);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saving Decimal Numbers as Integers

1 participant