Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

replace   text in javascript

Posted on 2012-03-20
6
Medium Priority
?
392 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 83

Expert Comment

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

Author Comment

by:eaweb
ID: 37744541
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 83

Expert Comment

by:leakim971
ID: 37744553
we remove   each time
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:eaweb
ID: 37744572
this how i get it

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

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

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 37744581
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 83

Expert Comment

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

885 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