Solved

replace   text in javascript

Posted on 2012-03-20
6
322 Views
Last Modified: 2012-03-22
hi,

i using below code to format numbers
roundNumber(formatNumbers($number, 3), 2).toFixed(2);

the issue is that the $number can come as   which is breaking the script. how must i rewrite the code to to check if the $number contains the text   and if yes change it to 000 else use the value of $number?
0
Comment
Question by:eaweb
  • 4
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
roundNumber(formatNumbers($number.replace(/ /g,""), 3), 2).toFixed(2);
0
 

Author Comment

by:eaweb
Comment Utility
when running the code i can get it as follow.
roundNumber(formatNumbers(1616161, 3), 2).toFixed(2);  --- ok
or
roundNumber(formatNumbers( , 3), 2).toFixed(2);  ---bad
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
we remove   each time
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:eaweb
Comment Utility
this how i get it

roundNumber(formatNumbers(100000000.replace(/ /g,""), 3), 2).toFixed(2);

roundNumber(formatNumbers( .replace(/ /g,""), 3), 2).toFixed(2);
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
ok, I understand, you mix php and javascript

put double quotes around :

roundNumber(formatNumbers("100000000".replace(/ /g,""), 3), 2).toFixed(2);

roundNumber(formatNumbers(" ".replace(/ /g,""), 3), 2).toFixed(2);

so :

roundNumber(formatNumbers("$number".replace(/ /g,""), 3), 2).toFixed(2);
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
it would be better(?) to put the "replace" inside your formatNumber function
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now