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

clean way to distinguish between float and int numbers? #95

Open
Av1shay opened this issue Apr 11, 2023 · 0 comments
Open

clean way to distinguish between float and int numbers? #95

Av1shay opened this issue Apr 11, 2023 · 0 comments

Comments

@Av1shay
Copy link

Av1shay commented Apr 11, 2023

Hi
I need to parse *fastjson.Value value to a string, in case of Number type is there an elegant and fast way check if the value is int number or float number?

func parseFastJsonVal(v *fastjson.Value) string {
	switch v.Type() {
        ...
	case fastjson.TypeNumber:
                 // if it's int number i want to return fmt.Sprintf("%d", v.GetInt())
                
                // if it's float i want to return fmt.Sprintf("%v", v.GetFloat64())
	}
	return ""
}

I can do naive stuff like checking explicitly if it's float or if it has a decimal point, but i wonder if there is a fastest way to check it based on the data i already got from parsing the JSON

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

1 participant