JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 16th, 2007, 09:40 PM
phpscripter phpscripter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 phpscripter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 53 m 38 sec
Reputation Power: 0
How to determine the number of decimal places?

Hi,
Is there a way to determine the number of decimal places e.g.:

xx.xxx = 3
x.x = 1

etc..

Cheers
Jan

Reply With Quote
  #2  
Old April 17th, 2007, 04:16 AM
mecanicu mecanicu is offline
anonymous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 244 mecanicu User rank is Private First Class (20 - 50 Reputation Level)mecanicu User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 12 h 21 m 10 sec
Reputation Power: 9
Hi phpscripter here is the JavaScript you always search for:
Javascript Code:
Original - Javascript Code
  1. // use dec_sep for internationalization
  2. function Decimals(x, dec_sep)
  3. {
  4.     var tmp=new String();
  5.     tmp=x;
  6.     if (tmp.indexOf(dec_sep)>-1)
  7.         return tmp.length-tmp.indexOf(dec_sep)-1;
  8.     else
  9.         return 0;
  10. }


If you trying to use Math for this you will discover that, because of numbers representation, you have to deal with some errors in multiplying with 10.

Hope it helps

Last edited by mecanicu : April 17th, 2007 at 04:18 AM.

Reply With Quote
  #3  
Old April 17th, 2007, 10:45 PM
phpscripter phpscripter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 phpscripter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 53 m 38 sec
Reputation Power: 0
That looks great, thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > How to determine the number of decimal places?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap