Skip to main content
Module

x/ddc_vim/deps.ts>fn.str2float

Dark deno-powered completion framework for neovim/Vim
Latest
function fn.str2float
import { fn } from "https://deno.land/x/ddc_vim@v4.3.1/deps.ts";
const { str2float } = fn;

Convert String {string} to a Float. This mostly works the same as when using a floating point number in an expression, see floating-point-format. But it's a bit more permissive. E.g., "1e40" is accepted, while in an expression you need to write "1.0e40". The hexadecimal form "0x123" is also accepted, but not others, like binary or octal. When {quoted} is present and non-zero then embedded single quotes before the dot are ignored, thus "1'000.0" is a thousand. Text after the number is silently ignored. The decimal point is always '.', no matter what the locale is set to. A comma ends the number: "12,345.67" is converted to 12.0. You can strip out thousands separators with substitute():

let f = str2float(substitute(text, ',', '', 'g'))

Returns 0.0 if the conversion fails.

Can also be used as a method:

let f = text->substitute(',', '', 'g')->str2float()

Parameters

denops: Denops
string: unknown
optional
quoted: unknown

Returns

Promise<number>