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

yyjson_get_real() returns zero (0) if you pass it a string containing an integer #192

Open
pmuvb opened this issue Dec 26, 2024 · 3 comments

Comments

@pmuvb
Copy link

pmuvb commented Dec 26, 2024

Describe the bug
yyjson_get_real() returns zero (0) if you pass it a string containing an integer.
e.g. if you pass "99" it will return 0, I believe it should return 99.0.

Your environment
Debian 12
Debian clang version 16.0.6

It you look at C++ std::strtod() that's how it works: if you pass "99" it will return double 99.0.

thanks.

@pmuvb pmuvb changed the title yyjson_get_real() returns zero (0) if you pass it an integer yyjson_get_real() returns zero (0) if you pass it a string containing an integer Dec 26, 2024
@ibireme
Copy link
Owner

ibireme commented Dec 27, 2024

You can use yyjson_get_num() to convert any numeric type to a double.

In contrast, yyjson_get_real(), yyjson_get_sint(), and yyjson_get_uint() do not perform type conversion, they return 0 if the numeric type doesn't match.

@pmuvb
Copy link
Author

pmuvb commented Dec 28, 2024

This is counter intuitive to standard C++ functions but I see, thank you.

@pmuvb
Copy link
Author

pmuvb commented Dec 28, 2024

The issues I have is the vendor sends me JSON containing a price, but if the price is a whole dollar (doesn't have cents) they send an integer, works now using yyjson_get_num().

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

2 participants