Tuesday, October 21, 2014

Datatype Conversion

Types Conversion Function:

1)isNan():Check to see if what is passed is not a number,return a boolean output

<script type="text/javascript">
document.write("111 IS:"+isNaN(111)+"<br>");
document.write("-111.45 IS:"+isNaN(-111.45)+"<br>");
document.write("Hello IS:"+isNaN("Hello")+"<br>");
</script>

2)eval():It convert String to Integer or Float
It Can Also Evalute the Expression include with a string.

<script type="text/javascript">
var Ans=eval("256/7*8");
document.write("The Correct Answer IS:"+Ans);
</script>

3)parseInt():Convert The String to Integer Value.
Return The First Integer Which is Contain in String.

<script type="text/javascript">
document.write("111.111 Value:"+parseInt(111.111)+"<br>");
document.write("123Good456 Value:"+ parseInt (123Good456)+"<br>");
document.write("Hello Value:"+ parseInt ("Hello")+"<br>");
</script>

4)parseFloat():Convert The String to Floating Point Number.
Return The First Floating Point Number  Which is Contain in String.

<script type="text/javascript">
document.write("111.111 Value:"+parseFloat(111.111)+"<br>");
document.write("123.45Good1 Value:"+ parseFloat(123.45Good1)+"<br>");
document.write("Hello Value:"+ parseFloat ("Hello")+"<br>");
</script>


No comments: