Jump to content

Help About Js Number


ltdangkhoa

Recommended Posts

i have 2 functions below, how can i keep the value of id not to be round figured

function a(){var id = 5324940297598675569;alert(id); // here the result is 5324940297598676000b(id);}function b(id){alert(id); // here the result is 5324940297598676000, i want to transfer value to function b as 5324940297598675569 not 5324940297598676000}

everyone, please help me! thanks alot and have a nice weekend

Link to comment
Share on other sites

i have 2 functions below, how can i keep the value of id not to be round figured
function a(){var id = 5324940297598675569;alert(id); // here the result is 5324940297598676000b(id);}function b(id){alert(id); // here the result is 5324940297598676000, i want to transfer value to function b as 5324940297598675569 not 5324940297598676000}

everyone, please help me! thanks alot and have a nice weekend

Well, apparently Javascript's Number type only allows for 16 significant digits. 16 digits is a whole lot. If you're not going to do operations with these numbers, try making it a String instead.
Link to comment
Share on other sites

Thanks Ingolme! I've tried to use String but somethings happend... see below

 function a(){				var id = new String();				id = "5324940297598675569";				document.getElementById("a").innerHTML = '<a href="java script:b(' + id + ')">' + id + '</a>'; <-- when i use this method the result auto covert id to 5324940297598676000								//  b(id); <-- but if when i use this one, the result is correct... but in my app, i don't want it load automatically like this			}function b(id){				document.getElementById("b").innerHTML = id;			}

Link to comment
Share on other sites

Guest FirefoxRocks
Try putting quotes around the id value:document.getElementById("a").innerHTML = '<a href="java script:b(\'' + id + '\')">' + id + '</a>';
Also, does it make sense to put a link in a link? (Setting the innerHTML of a link to the html of a link?)
document.getElementById("a").href = "java script:b('"+id+"')>";document.getElementById("a").innerHTML = id;

I also forgot how to use document.getElementById because I'm so used to jQuery :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...