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

"c" format does not work as expected #116

Closed
ethanabrooks opened this issue May 31, 2021 · 4 comments
Closed

"c" format does not work as expected #116

ethanabrooks opened this issue May 31, 2021 · 4 comments

Comments

@ethanabrooks
Copy link

ethanabrooks commented May 31, 2021

According to the docs:

c - converts the integer to the corresponding unicode character before printing

In my code,

console.log(format("c")(97));

Just prints 97.
I was expecting something along the lines of python:

>>> chr(97)
'a'
@Fil
Copy link
Member

Fil commented May 31, 2021

In C, python and PHP printf("%c", 97) give "a". In

"c": (x) => x + "",
it gives "97".
The tests are only for a 1-char string input, so it looks like an oversight.

@mbostock
Copy link
Member

The code is doing what is intended here, but it looks like we forgot to update the documentation accordingly. This was changed in e247671.

@ethanabrooks
Copy link
Author

I see. Is there a way to do achieve the same effect as python's chr function with d3-format?

@mbostock
Copy link
Member

mbostock commented Dec 4, 2021

Is there a way to do achieve the same effect as python's chr function with d3-format?

Not currently, but you could use String.fromCharCode(97) in conjunction with type c.

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

3 participants