Skip to content

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

@Av1shay

Description

@Av1shay

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions