Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
changing £12.6 to £12.60
Old 12-16-2008, 07:06 AM changing £12.6 to £12.60
jason_bristol's Avatar
Ultra Talker

Latest Blog Post:
New site - ConnectFrench.com
Posts: 310
Name: Jason Eyermann
Location: england bristol
Trades: 0
I have created a javascript priceupdater on a site and when the price ends in 0 the 0 is cut off. I've been looking for a function to keep the 0 added?

EG price is £12.60

and my dynamic price updater shows £12.6 I need it to change to £12.60
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
jason_bristol is offline
Reply With Quote
View Public Profile Visit jason_bristol's homepage!
 
 
Register now for full access!
Old 12-16-2008, 09:45 AM Re: changing £12.6 to £12.60
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
if (price.lastIndexOf(".") == 2) {
 	price += "0" ;
}
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 12-16-2008 at 09:46 AM..
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-16-2008, 07:05 PM Re: changing £12.6 to £12.60
jason_bristol's Avatar
Ultra Talker

Latest Blog Post:
New site - ConnectFrench.com
Posts: 310
Name: Jason Eyermann
Location: england bristol
Trades: 0
I couldn't get the code below to work. However....

Code:
if (price.lastIndexOf(".") == 2) {
 	price += "0" ;
}
I've found an inbuilt function

Code:
price.toFixed(2);
This is useful for floating points. This method will keep your number to 2 digits after the point.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
jason_bristol is offline
Reply With Quote
View Public Profile Visit jason_bristol's homepage!
 
Old 12-17-2008, 10:33 PM Re: changing £12.6 to £12.60
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
Most programming languages support something like "printf" which gives you formatted printing. I looked around and found something kinda neat. This script (source at the bottom) will allow you to use standard sprintf function calls.

http://www.webtoolkit.info/javascript-sprintf.html

Hope it helps
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to changing £12.6 to £12.60
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18557 seconds with 12 queries