From bf8e099b9c8b3c60d60b3712b4fc97b052c39887 Mon Sep 17 00:00:00 2001 From: julieng Date: Tue, 3 Aug 2021 08:03:23 +0200 Subject: convert content to md --- .../reference/global_objects/math/trunc/index.md | 101 +++++++++------------ 1 file changed, 42 insertions(+), 59 deletions(-) (limited to 'files/fr/web/javascript/reference/global_objects/math/trunc') diff --git a/files/fr/web/javascript/reference/global_objects/math/trunc/index.md b/files/fr/web/javascript/reference/global_objects/math/trunc/index.md index c78b0cb6ec..64c918039a 100644 --- a/files/fr/web/javascript/reference/global_objects/math/trunc/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/trunc/index.md @@ -11,84 +11,67 @@ tags: translation_of: Web/JavaScript/Reference/Global_Objects/Math/trunc original_slug: Web/JavaScript/Reference/Objets_globaux/Math/trunc --- -
{{JSRef}}
+{{JSRef}} -

La fonction Math.trunc() retourne la troncature entière d'un nombre en retirant sa partie décimale.

+La fonction **`Math.trunc()`** retourne la troncature entière d'un nombre en retirant sa partie décimale. -

Math.trunc(x)={xsix0xsix<0\mathtt{\operatorname{Math.trunc}(x)} = \begin{cases} \left\lfloor x \right\rfloor & \text{if} & x \geq 0 \\ \left\lceil x \right\rceil & \text{if} &x < 0 \end{cases}

+Math.trunc(x)={xsix0xsix<0\mathtt{\operatorname{Math.trunc}(x)} = \begin{cases} \left\lfloor x \right\rfloor & \text{if} & x \geq 0 \\ \left\lceil x \right\rceil & \text{if} &x < 0 \end{cases} -
{{EmbedInteractiveExample("pages/js/math-trunc.html")}}
+{{EmbedInteractiveExample("pages/js/math-trunc.html")}} -

Syntaxe

+## Syntaxe -
Math.trunc(x)
+ Math.trunc(x) -

Paramètres

+### Paramètres -
-
x
-
Un nombre.
-
+- `x` + - : Un nombre. -

Valeur de retour

+### Valeur de retour -

La partie entière du nombre passé en argument.

+La partie entière du nombre passé en argument. -

Description

+## Description -

Contrairement aux autres méthodes {{jsxref("Math.floor()")}}, {{jsxref("Math.ceil()")}} et {{jsxref("Math.round()")}}, Math.trunc() fonctionne de façon très simple : la partie décimale du nombre est retirée et on conserve la partie entière (que le nombre soit positif ou négatif).
-
- Ainsi, si l'argument est un nombre positif, Math.trunc() sera équivalent à Math.floor(), sinon Math.trunc() sera équivalent à Math.ceil().

+Contrairement aux autres méthodes {{jsxref("Math.floor()")}}, {{jsxref("Math.ceil()")}} et {{jsxref("Math.round()")}}, `Math.trunc()` fonctionne de façon très simple : la partie décimale du nombre est retirée et on conserve la partie entière (que le nombre soit positif ou négatif). -

On notera que l'argument passé à la méthode est converti en nombre de façon implicite.

+Ainsi, si l'argument est un nombre positif, `Math.trunc()` sera équivalent à `Math.floor()`, sinon `Math.trunc()` sera équivalent à `Math.ceil()`. -

trunc() est une méthode statique de Math, elle doit toujours être utilisée avec la syntaxe Math.trunc(), elle ne doit pas être utilisée comme la méthode d'un objet qui aurait été instancié (Math n'est pas un constructeur).

+On notera que l'argument passé à la méthode est converti en nombre de façon implicite. -

Exemples

+`trunc()` est une méthode statique de `Math`, elle doit toujours être utilisée avec la syntaxe `Math.trunc()`, elle ne doit pas être utilisée comme la méthode d'un objet qui aurait été instancié (`Math` n'est pas un constructeur). -

Utiliser Math.trunc()

+## Exemples -
Math.trunc(13.37);   // 13
+### Utiliser `Math.trunc()`
+
+```js
+Math.trunc(13.37);   // 13
 Math.trunc(42.84);   // 42
 Math.trunc(0.123);   //  0
 Math.trunc(-0.123);  // -0
 Math.trunc("-1.123");// -1
 Math.trunc(NaN);     // NaN
 Math.trunc("toto");  // NaN
-Math.trunc();        // NaN
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaire
{{SpecName('ES2015', '#sec-math.trunc', 'Math.trunc')}}{{Spec2('ES2015')}}Première définition.
{{SpecName('ESDraft', '#sec-math.trunc', 'Math.trunc')}}{{Spec2('ESDraft')}}
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Math.trunc")}}

- -

Voir aussi

- - +Math.trunc(); // NaN +``` + +## Spécifications + +| Spécification | État | Commentaire | +| ---------------------------------------------------------------------------- | ---------------------------- | -------------------- | +| {{SpecName('ES2015', '#sec-math.trunc', 'Math.trunc')}} | {{Spec2('ES2015')}} | Première définition. | +| {{SpecName('ESDraft', '#sec-math.trunc', 'Math.trunc')}} | {{Spec2('ESDraft')}} | | + +## Compatibilité des navigateurs + +{{Compat("javascript.builtins.Math.trunc")}} + +## Voir aussi + +- {{jsxref("Math.abs()")}} +- {{jsxref("Math.ceil()")}} +- {{jsxref("Math.floor()")}} +- {{jsxref("Math.round()")}} +- {{jsxref("Math.sign()")}} -- cgit v1.2.3-54-g00ecf