Skip to main content

sheet-ref

Number format

正数格式;负数格式;零值格式;文本格式
<POSITIVE>;<NEGATIVE>;<ZERO>;<TEXT>
#.###.00_);[Red](#.###.00);0.00;"gross receipts for"@
Positive Negative Zero Text
  • #.###.00_)
    • # 占位符,如果数字中没有相应的位数,则不显示。
    • .:小数点分隔符(不同区域可能用逗号 , 表示)。
    • 00:强制显示两位小数。
    • _:添加一个空格,用于对齐正数和负数。
    • _ 后的 ) 表示空格的宽度与右括号相同。
  • @ 表示当前单元格的内容
  • #.???
SymbolResultDescription
0Digit or Zero7 + 00 -> "07"
#Digit if needed7 + ## -> "7"
?Digit or Space7 + ?? -> " 7"
.Decimal point
,Thousands separator1234 + #,##0 -> "1,234". locale.
%Percentage.7 + 0% -> "70%"
E-, E+Exponential format12200000 + 0.00E+00 -> "1.22E+07"
$, -, +, /, (, ), Pass-throughThe symbol is printed as-is.
\Escape
*FillRepeat the next character to fill the column; numfmt emits nothing when this is used.
_Skip widthSkip the width of the next character. By default numfmt emits only a single space when this is used.
"text"Pass-throughPass through whatever text is inside the quotation marks as-is. 7 formatted with 0 "bells" will emit "7 bells"
@Text valueWhen value is a text, emit it as is: foo formatted with "bar"@"bar" will emit "barfoobar"
yyYears2024 -> 24
yyyyYears2024 -> 2024
mMonth1–12
mmMonth01–12
mmmShort monthJan–Dec. locale
mmmmMonth nameJanuary–December. locale
mmmmmMonth nameJ–D. locale
dDays1–31
ddDays01–31
dddWeekdaysSun–Sat
ddddWeekdaysSunday–Saturday
hHours0–23, 1–12
hhHours00–23, 01–12
mMinutes0–59
mmMinutes00–59
sSeconds0–59
ssSeconds00–59
AM/PM12h clockAM or PM.
A/P12h clockA or P.
[h]HoursElapsed time in hours
[m]MinutesElapsed time in minutes
[s]SecondsElapsed time in seconds

import { format } from 'numfmt';

// 1,234.56
console.log(format('#,##0.00', 1234.56));