Sathish David Kumar N
asked on
check whether the number having is fractional value or not in java script
check whether the number having is fractional value or not in java script
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry mine code has error. Should be
var val = 74;
WScript.Echo((val % 2 != 0 ? 'has' : 'no')+' fraction') ;
why WScript.Echo???
alert will do just fine
alert will do just fine
@gurvinder
<script>
function check(val1) {
if ( Math.round(parseInt( val1)) != val1) {
alert("it is a fractional value");
}
else {
alert("It is not");
}
}
check("09"); // oops?
</script>
<script>
function check(val1) {
if ( Math.round(parseInt( val1)) != val1) {
alert("it is a fractional value");
}
else {
alert("It is not");
}
}
check("09"); // oops?
</script>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is nicer to read:
String(val).indexOf('.')
than
(val + "").indexOf('.')
String(val).indexOf('.')
than
(val + "").indexOf('.')
but this will not tell me if this is a valid number at first place since 1.1.1.3 will also qualify as a fraction
is typecasting is supported in javascript also????
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry, it has to be
function check(val1)
{
alert(Math.round(parseInt( val1,10)));
if ( Math.round(parseInt( val1, 10)) != val1) {
alert("it is a fractional value");
}
else {
alert("It is not");
}
}
function check(val1)
{
alert(Math.round(parseInt(
if ( Math.round(parseInt( val1, 10)) != val1) {
alert("it is a fractional value");
}
else {
alert("It is not");
}
}
Yep :)
08 and 09 are invalid octal numbers
08 and 09 are invalid octal numbers
Here 08 and 09 are considered a decimal number and v r checking 4r number is fraction or not, not 4r the octal or hexadecimal number.
My comment was directed at Gurvinder, as a response to his response on my comment http:#a26198191
Your script would work since you a) do a test for isNaN and b) test the string for a "."
However your script also tells me 1. is a fraction..
alert("1. is a fraction:"+isFraction("1." ));
Your script would work since you a) do a test for isNaN and b) test the string for a "."
However your script also tells me 1. is a fraction..
alert("1. is a fraction:"+isFraction("1."
but if i use " Math.round((parseInt( val,10))+"") != val" then for "1.0' it give it 1.0 is not a fraction
similarly 1.0 will give a fraction if we check for the index of '.'
will this not work
str= "1.0";
var myArray = str.match(/[0-9]*\.[1-9][0 -9]*/g)
str= "1.0";
var myArray = str.match(/[0-9]*\.[1-9][0
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the point of
if(Boolean(val.substring(v al.indexOf (val)+1, val.length)))
???
if(Boolean(val.substring(v
???
if condition should be if(Boolean(val.substring(v al.indexOf (val)+1, val.length-1))) not
if(Boolean(val.substring(v al.indexOf (val)+1, val.length)))
if(Boolean(val.substring(v
to check for the value like "1."
Sorry, does not make any sense to me
ASKER
any update !!
What do you mean.
Take one and try it, give points if happy.
I believe mine is complete http:a26200697
Take one and try it, give points if happy.
I believe mine is complete http:a26200697
ASKER
sorry mplungjan i select ur code as multiple selection but its not apper here i dont know how to revert back the point ..
can u put request attention i will assign point to u !! ( ur code also helped me )
can u put request attention i will assign point to u !! ( ur code also helped me )
ASKER
Thanks .....
HTH
Ivo Stoykov
Open in new window