Skip to content

Instantly share code, notes, and snippets.

View lukewlms's full-sized avatar

Luke Williams lukewlms

View GitHub Profile
@lukewlms
lukewlms / ExpoLocaleNumbers.ts
Created June 21, 2019 18:54
Parsing and reading of localized numbers with Expo
import { locale } from "expo-localization";
const thousandsSeparator = (1000).toLocaleString(locale)[1] === "," ? "," : ".";
const decimalSeparator = thousandsSeparator === "." ? "," : ".";
export function parseLocaleNumber(stringNumber: string) {
return Number(
stringNumber
.replace(new RegExp(`\\${thousandsSeparator}`, "g"), "")
.replace(new RegExp(`\\${decimalSeparator}`), "."),