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's are truncated #913

Open
weepy opened this issue Sep 23, 2022 · 6 comments
Open

Float's are truncated #913

weepy opened this issue Sep 23, 2022 · 6 comments

Comments

@weepy
Copy link

weepy commented Sep 23, 2022

The %d formatter coerces any floating point number such as 0.3123 to an integer.

The documentation should mention this.

The only way I could find to print the full number is to use %o .

It would be nice to have better printf style control e.g. %d3 to print 3 sig figures.

@Qix-
Copy link
Member

Qix- commented Sep 23, 2022

%f?

@Qix-
Copy link
Member

Qix- commented Sep 23, 2022

Also, I can't reproduce.

const debug = require('debug')('foo:bar');

debug('%d', 1.23456);
debug('%f', 1.23456);

image

@weepy
Copy link
Author

weepy commented Sep 23, 2022

Ok - I get the same as you in node

In the browser i get 1 for %d and 1.2345 for %f

@Qix-
Copy link
Member

Qix- commented Sep 23, 2022

Right so the browser implementation is actually more correct. We target printf()'s specifiers. %d means "integer". %f means "floating point number". I don't remember if debug understands %.06f (it's been a while) but that would be the way to specify precision.

@weepy
Copy link
Author

weepy commented Sep 23, 2022 via email

@Qix-
Copy link
Member

Qix- commented Sep 23, 2022

PR welcome.

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

No branches or pull requests

2 participants