Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Rounding a Number to a String with N decimal places

Reply
Thread Tools

Rounding a Number to a String with N decimal places

 
 
Dr John Stockton
Guest
Posts: n/a
 
      08-15-2004

When rounding (or truncating) a number which may be either positive or
negative, it is sometimes necessary to round either towards plus
infinity or towards minus infinity. But those are special cases.

Normally, however, rounding should be symmetrical about zero; rounding X
should give the same digits as rounding -X, for all X.

Some of the signed routines which have been quoted here and elsewhere
are unsymmetrical.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
G Roydor
Guest
Posts: n/a
 
      08-15-2004


Dr John Stockton a écrit:
> When rounding (or truncating) a number which may be either positive or
> negative, it is sometimes necessary to round either towards plus
> infinity or towards minus infinity. But those are special cases.
>
> Normally, however, rounding should be symmetrical about zero; rounding X
> should give the same digits as rounding -X, for all X.


Non

2 < 2.x < 3 => 2 ou 3

-3 < -2.x < -2 => 3 ou 2

GR


>
> Some of the signed routines which have been quoted here and elsewhere
> are unsymmetrical.
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? FAQ server Javascript 52 02-07-2007 04:57 PM
<faqentry>How do I convert a Number into a String with exactly 2 decimal places?</faqentry> VK Javascript 19 01-30-2007 07:55 PM
FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? FAQ server Javascript 6 11-03-2006 11:14 PM
FAQ 3.5. - How do I convert a Number into a String with exactly 2 decimal places? FAQ server Javascript 1 08-19-2006 07:28 AM
Rounding up to 2 decimal places Gary Mayor Perl Misc 6 12-10-2003 10:55 AM



Advertisments