pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt

-4bdf-a490-390a1aebf6dd/airgap.js" >

Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.

View in English Always switch to English

Number.parseInt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since setembro de 2015.

O método Number.parseInt() converte um argumento de string e retorna um inteiro da raiz ou base específica.

Experimente

function roughScale(x, base) {
  const parsed = Number.parseInt(x, base);
  if (Number.isNaN(parsed)) {
    return 0;
  }
  return parsed * 100;
}

console.log(roughScale(" 0xF", 16));
// Expected output: 1500

console.log(roughScale("321", 2));
// Expected output: 0

Sintaxe

Number.parseInt(string,[ radix])

Parâmetros

string

O valor a ser convertido. Se este argumento não for uma string, então ele é convertido a um usando a operação abstrata ToString. O espaço em branco inicial neste argumento é ignorado.

radix_ Optional_

Um inteiro entre 2 e 36 que representa a raiz (a base no sistema numérico matemático) de uma string. Tome cuidado—o padrão não é 10!

Valor de retorno

Um inteiro convertido de uma dada string.

Se a radix é menor que 2 ou maior que 36, e o primeiro caracter que não é um espaço em branco não puder ser convertido para um número, NaN é retornado.

Polyfill

js
if (Number.parseInt === undefined) {
  Number.parseInt = window.parseInt;
}

Exemplos

Number.parseInt vs parseInt

Este método tem a mesma funcionalidade que o método global parseInt():

js
Number.parseInt === parseInt; // true

e é parte do ECMAScript 2015 (sua proposta é a modularização dos globais). Por favor veja parseInt() para mais detalhes e exemplos.

Especificações

Specification
ECMAScript® 2027 Language Specification
# sec-number.parseint

Compatibilidade com navegadores

Veja também

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy