therealwesfoster Posted January 16, 2008 Share Posted January 16, 2008 I'm wanting to restrice how long a dynamic money amount can be. For instance, I want $2.4200000000000004 to be $2.42. I know that you can do this in php using the sprintf function, but how would you go about doing this in javascript? Thanks Link to comment https://forums.phpfreaks.com/topic/86237-solved-sprintf-in-javascript/ Share on other sites More sharing options...
phpQuestioner Posted January 16, 2008 Share Posted January 16, 2008 <script language="javascript"> var original=2.4200000000000004; var change=Math.round(original*100)/100; alert("$"+change+""); // you can take this our; just for demo purposes </script> Link to comment https://forums.phpfreaks.com/topic/86237-solved-sprintf-in-javascript/#findComment-440494 Share on other sites More sharing options...
therealwesfoster Posted January 16, 2008 Author Share Posted January 16, 2008 Much appreciated. Worked like a charm. So simple. Thanks Link to comment https://forums.phpfreaks.com/topic/86237-solved-sprintf-in-javascript/#findComment-440499 Share on other sites More sharing options...
phpQuestioner Posted January 16, 2008 Share Posted January 16, 2008 your welcome Link to comment https://forums.phpfreaks.com/topic/86237-solved-sprintf-in-javascript/#findComment-440600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.