Skip to main content
Module

x/denops_std/function/mod.ts>str2nr

📚 Standard module for denops.vim
Go to Latest
function str2nr
import { str2nr } from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";

Convert string {string} to a number. {base} is the conversion base, it can be 2, 8, 10 or 16. When {quoted} is present and non-zero then embedded single quotes are ignored, thus "1'000'000" is a million.

When {base} is omitted base 10 is used. This also means that a leading zero doesn't cause octal conversion to be used, as with the default String to Number conversion. Example:

let nr = str2nr('0123')

When {base} is 16 a leading "0x" or "0X" is ignored. With a different base the result will be zero. Similarly, when {base} is 8 a leading "0", "0o" or "0O" is ignored, and when {base} is 2 a leading "0b" or "0B" is ignored. Text after the number is silently ignored.

Returns 0 if {string} is empty or on error.

Can also be used as a method:

GetText()->str2nr()

Parameters

denops: Denops
string: unknown
optional
base: unknown
optional
quoted: unknown

Returns

Promise<number>