# Rounding a Number to a String with N decimal places

Discussion in 'Javascript' started by Dr John Stockton, Aug 15, 2004.

1. ### Dr John StocktonGuest

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.

--
<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.

Dr John Stockton, Aug 15, 2004

2. ### G RoydorGuest

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.
>

G Roydor, Aug 15, 2004