Skip to content
WingoUI
ComponentsTemplatesDocsPricingAI agentsBlogChangelogContact
Components
Buttons & Actions
ButtonButton GroupCopy ButtonDelete ButtonTheme ToggleToggleToggle Group
Inputs
Avatar UploadCalendarCheckboxColor PickerComboboxCountry SelectCron PickerCurrency InputDate PickerDate Range PickerDate Time PickerDuration PickerEmail InputEmoji PickerFile UploadFilter BuilderInputInput GroupListboxMasked InputMention InputMonth PickerMulti SelectNumber InputOTP InputPassword InputPhone InputRadio GroupRatingSearch InputSegmented ControlSelectSignature PadSliderSwitchTag InputTextareaTime PickerTimezone SelectTree Select
Forms
Address InputBooking WidgetCSV ImportFieldForm WizardInline EditInvoice line itemsRich Text EditorSchema Builder
Navigation
Back To TopBounce SidebarBreadcrumbCommand MenuGlobal SearchGooey NavHook SidebarNav MenuNav TabsPaginationProximity SidebarScroll ProgressSidebarStepsTable Of ContentsTabsTopbarUser MenuWorkspace Switcher
Overlays
Alert DialogContext MenuDialogDrawerDropdown MenuFamily DrawerHover CardPopoverShare DialogSheetShortcuts DialogTooltipTour
Feedback
AlertBannerCookie ConsentEmoji ReactionEmpty StateNotification BellNotification CenterProgressRoute ProgressSetup ChecklistSkeletonSpinnerToast
Data Display
Approval FlowAvatarBadgeCalendar ViewCode BlockComment ThreadContact cardCountdownDescription ListDiff ViewerFile ListFile managerFolderGanttJSON ViewerKbdLog ViewerMarkdownPresenceSchedulerTagTimelineTree View
Tables & Lists
Audit LogData TableDeal PipelineEditable GridKanbanListMembers tablePermissions MatrixTableTask ListVirtual List
Charts & Stats
Animated CounterArea chartBar chartDonut chartFunnel chartGaugeGitHub ActivityHeatmap calendarLeaderboardLine chartRadar chartRadial barSparklineStat CardTrackerTrend badge
Layout
AccordionApp ShellCardCollapsibleDetail LayoutEntity HeaderPage HeaderScroll AreaSeparatorSettings LayoutSplit ViewToolbar
Media
Audio PlayerCarouselCSV ViewerDOCX EditorDOCX ViewerExcel ViewerFile SystemImage compareImage CropperImage GalleryImage LightboxLocation MapPDF ViewerPowerPoint ViewerQR CodeStep PlayerVideo Player
AI Kit
Agent Status CardChat MessageChat ThreadChat WidgetConversation ListFluid OrbGrid RevealMatrix OrbModel PickerPrompt InputReasoning IndicatorRule BuilderSuggestion ChipsTool Call TimelineUsage MeterVoice InputWorkflow Canvas
Text & Effects
Background PatternGravity LettersMarqueeTerminalText AnimateText Rotate
Mobile
Action SheetBottom Tab BarFABHaptic ButtonHero HeaderInstall PromptLarge Title HeaderNotification BannerOnboarding CarouselPicker WheelPull To RefreshSlide To ConfirmSticky CTA BarSwipe DeckSwipeable Tabs
Commerce
Cart drawerCategory pickerCheckout stepsCoupon inputFavorite buttonFilter panelListing cardListing gridOrder trackerPricePrice rangePricing tableProduct galleryQuantity stepperReviewsSeller card
Marketing Sections
App Download SectionBlog Cards SectionCTA SectionFAQ SectionFeature GridFeature ShowcaseHero SectionIntegrations SectionLogo CloudMarketing FooterMarketing HeaderMarketing SectionNewsletter SectionPricing SectionStats SectionSteps SectionTeam SectionTestimonials SectionTimeline SectionVideo Section
Blocks
Admin Dashboard PageAdmin ShellAI Chat PageAPI Keys PageAutomation Builder PageCheckout PageCRM Contact PageCRM Pipeline PageError PagesInbox PageInvoice PageKPI DashboardListing Detail PageLogin PageMarketplace Home PageMarketplace Search PageMarketplace ShellMobile App HomeOnboarding FlowOrder History PagePost Listing WizardPricing PageProfile PageRegister PageSettings PageUsers Admin Page
Templates
About PageAcademy PageAccessibility PageAffiliate PageAgency PageAI Product PageAppointment Booking PageBlog PageBlog Post PageBug Bounty PageCareers PageChangelog PageCommunity PageCompare PageContact PageCustomer Story PageCustomers PageDemo Booking PageDevelopers PageDocs Home PageDownload PageEnterprise PageEvents PageExperts PageFAQ PageFeature PageGlossary PageHelp Article PageHelp Center PageHome Services PageImpact PageIntegration Detail PageIntegrations PageJob Detail PageLanding PageLaunch PageLegal PageManifesto PagePortfolio PagePress PageProduct Tour PagePromo PageReal Estate PageReferral PageResearch Report PageRestaurant PageRoadmap PageROI Calculator PageSecurity PageSolutions PageStartups PageStatus PageStorefront PageSwitch PageTemplate Gallery PageTravel PageWaitlist PageYear in Review Page
Hooks & Utilities
AI ChatChart kitCommerceDate utilsFile exportFile typesFiltersForm validationHapticsInvoicingMotion presetsNavigationNumber formatRelative timeRomanian locationsSpreadsheetText matchTonesUIProvideruseClipboarduseConsentuseControllableStateuseCooldownuseDebounceuseKeyboardInsetuseLocaleuseLongPressuseMediaControlsuseMediaQueryuseOverflowItemsusePersistedStateuseScrollEdgesuseScrollStateuseSelectionuseShortcutuseStickToBottom
GalleryTheme

Hooks & Utilities

Number format

Hooks & Utilities

Number format TypeScript helper for React

NavigationRelative time
Live props
Options
locale
currency
maxDecimals2
  1. Home
  2. Components
  3. Hooks & Utilities
  4. Number format
Free

Number format TypeScript helper for React

v1.0.0·Added in 1.0.0

Locale-aware number helpers: cached Intl formatting, parsing what people type, step math and currency affixes.

Type an amount: the field groups thousands as you type in the chosen locale and the caret never jumps. A dot or a comma both work as the decimal point, like on a phone keypad. The rows below show the parsed number, the same value formatted three ways and how the locale writes the currency.

Number format is a free React helper in the React hooks and utilities category, written in TypeScript for React 19. It installs as source with npx wingo-ui@latest add number-format.

Add to a project

Requirements: React 19, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup

npx wingo-ui@latest add number-format

Usage

Import parseNumber from @/lib/number-format.

import { formatNumber, getCurrencyParts, parseNumber } from "@/lib/number-format"

const price = parseNumber("1,234.5", "en-US") // 1234.5
parseNumber("1.234,5", "de-DE") // 1234.5
formatNumber(price, "en-US", { style: "currency", currency: "USD", currencyDisplay: "narrowSymbol" }) // "$1,234.50"
getCurrencyParts("USD", "en-US") // { symbol: "$", position: "prefix", spaced: false, fractionDigits: 2 }
getCurrencyParts("RON", "ro-RO") // { symbol: "lei", position: "suffix", spaced: true, fractionDigits: 2 }

API

  • localedefault "en-US"
    string

    The demo's locale. Every helper takes an optional locale; pass the one from useLocale so server and browser agree.

  • currencydefault "USD"
    string

    An ISO 4217 code for getCurrencyParts and currency formatting.

  • maxDecimalsdefault 2
    number

    formatEditable's maxDecimals: decimals kept while typing; extra ones are cut, not rounded.

  • parseNumber
    (text: string, locale?: string) => number | null

    What someone typed, as a number (null when empty or not a number). The locale's decimal separator wins; without it a lone "." or "," before exactly three digits groups thousands ("1.234" = 1234 in de-DE) and anything else is a decimal point ("12.5" = 12.5). Symbols, units, spaces and "%" are ignored; the unicode minus works.

Parts

  • formatNumber

    function

    Intl formatting with a cached formatter. formatNumber returns "" for null and NaN so an empty field stays empty. Signature: (value: number | null | undefined, locale?: string, options?: Intl.NumberFormatOptions) => string.

  • getNumberFormatter

    function

    Intl formatting with a cached formatter. formatNumber returns "" for null and NaN so an empty field stays empty. Signature: (locale?, options?) => Intl.NumberFormat.

  • getNumberSeparators

    function

    The locale's characters: en-US "," and ".", de-DE "." and ",", fr-FR a narrow space and ",". Signature: (locale?: string) => { group: string; decimal: string; minus: string }.

  • getCurrencyParts

    function

    How a locale writes a currency, for a field's prefix or suffix: USD in en-US is "$" before the number, RON in ro-RO is "lei" after it with a space. display defaults to narrowSymbol ("$", "€", "lei"); Intl's own default would print "RON". Signature: (currency: string, locale?: string, display?: "symbol" | "narrowSymbol" | "code" | "name") => { symbol: string; position: "prefix" | "suffix"; spaced: boolean; fractionDigits: number }.

  • formatEditable

    function

    Re-formats a field's text while someone types: groups the integer part, keeps a trailing decimal separator ("12,") and trailing zeros ("12,50"), turns a typed "." into the locale decimal on an english keypad. Signature: (text: string, locale?: string, options?: { maxDecimals?: number; grouping?: boolean; allowNegative?: boolean }) => string.

  • digitsBeforeCaret

    function

    Keep the caret in place across a re-format: count the digits (and the decimal separator) before it, re-format, then put it back after the same count. Signature: (text: string, caret: number, locale?: string) => number.

  • caretAfterDigits

    function

    Keep the caret in place across a re-format: count the digits (and the decimal separator) before it, re-format, then put it back after the same count. Signature: (text: string, count: number, locale?: string) => number.

  • clamp

    function

    Step math without float noise: roundTo(0.1 + 0.2, 2) is 0.3, snapToStep(0.35, 0.1) is 0.4, decimalsOf(0.05) is 2 (the precision a step implies). Signature: (value, min?, max?).

  • roundTo

    function

    Step math without float noise: roundTo(0.1 + 0.2, 2) is 0.3, snapToStep(0.35, 0.1) is 0.4, decimalsOf(0.05) is 2 (the precision a step implies). Signature: (value, decimals).

  • snapToStep

    function

    Step math without float noise: roundTo(0.1 + 0.2, 2) is 0.3, snapToStep(0.35, 0.1) is 0.4, decimalsOf(0.05) is 2 (the precision a step implies). Signature: (value, step, origin?).

  • decimalsOf

    function

    Step math without float noise: roundTo(0.1 + 0.2, 2) is 0.3, snapToStep(0.35, 0.1) is 0.4, decimalsOf(0.05) is 2 (the precision a step implies). Signature: (value) => number.

Examples

One amount, six locales

formatNumber with style currency prints the same euro amount with each locale's separators and symbol position.

Parsing pasted text

parseNumber reads amounts the way people type them in each locale and returns null for anything that is not a number.

Currency parts

getCurrencyParts tells a money input where the symbol goes and how many decimals the currency uses.

Dependencies

No dependencies beyond React.

Files

  • lib/number-format.ts

FAQ

Is the Number format helper free?

Yes. The source is free and needs no account: copy it from the Code tab or install it with the CLI.

How do I install Number format?

Run npx wingo-ui@latest add number-format. With shadcn, run npx shadcn@latest add https://wingo-ui.com/r/number-format.json.

See also

Text matchlibDate utilslibuseLocalehook

Used in

Listing cardGaugeSliderFavorite buttonMarketplace Home PageMobile App HomeKanbanFile managerLocation MapStat CardSparklineOrder tracker

and 67 more.

More React hooks and utilities

Relative timelibRomanian locationslibSpreadsheetlibToneslibUIProviderlibuseClipboardhook
All 36 React hooks and utilities

Articles using this component

  • React Currency Input: Intl Formatting Without Caret Jumps

    Component guides · Oct 16, 2026 · 10 min read

PreviousNavigationNext Relative time
$

Separators in en-US: decimal “.”, thousands “,”

parseNumber1234.5
formatNumber1,234.5
currency$1,234.50
percent (÷100)1,234.5%
getCurrencyParts$ · prefix · 2 dec.