1

Actually we are using d3 with grails. there is scenario like we need to sort the given input according to integer, float and string.

I can check weather the input is number or string with `

if(typeof(d["colorField"])=='number'){
  L_KEY_NUMERIC = true;
}else{
   L_KEY_NUMERIC = true;
}

but this is failing for double value. double values are not getting sorted properly.

So, i need to check whether the key is double or integer using jquery. currently I'am using sort() method which sorts for integer normally but not for double values. once i detect the key is double or float which sort method i need to use.

And how to sort float key via ascending order in jquery.

Any help appreciated.

0

2 Answers 2

0

You should use d["colorField"] % 1 === 0 to check if key is number:

if(d["colorField"] % 1 === 0){
 //if number is integer 
 L_KEY_NUMERIC = true;
}else{
 //if number is float
 L_KEY_NUMERIC = true;
}
Sign up to request clarification or add additional context in comments.

10 Comments

You have given answer to check number or float numbers.
if part to check number else part for not number
My question was different. I know it number but after that how can I check key is integer number or float number.
that is what it does. if its integer, it will go in if part for float it will go in else part.
Thanks. For quick response will check now.
|
0

Or you could use parseFloat(string)

e.g.
if (!isNan(parseFloat(string))){
  //your code here
}

Comments