Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float decimal places precision in node #761

Closed
hsilva7 opened this issue Oct 4, 2019 · 3 comments
Closed

float decimal places precision in node #761

hsilva7 opened this issue Oct 4, 2019 · 3 comments

Comments

@hsilva7
Copy link

hsilva7 commented Oct 4, 2019

I am trying to dump a node into a file with float values.

YAML::Node node;
node["Map"]["FloatValue"] = 123.456;

std::ofstream fout("file.yaml");
fout << node;

The output that I get is

Map:
    FloatValue: 123.456001

Is there anyway I can set the precision in a node?

@jbeder
Copy link
Owner

jbeder commented Oct 4, 2019

emitter << YAML::Precision(3) << node;

It's only when you're using an emitter.

Also, please ask questions like this on Stack Overflow.

@jbeder jbeder closed this as completed Oct 4, 2019
@bbchung
Copy link

bbchung commented Jun 26, 2022

emitter << YAML::Precision(3) << node;

It's only when you're using an emitter.

Also, please ask questions like this on Stack Overflow.

this is not working for above case actually (in 0.7.0), precision setting not work in YAML::Node type
image
image

@giorgosHadji
Copy link

Also having similar issue with double

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

No branches or pull requests

4 participants