本文へ移動
日本語

数値・日付・金額の表示形式ガイドライン

フォーマッター

値を入力。1 行が 1 つの形式で、4 言語を並べて表示します。

値の種類を選んで入力します。表には英語、簡体字中国語、スペイン語、日本語でそれぞれの形式が表示され、形式名の下にその形式のルールがあります。

数値
形式English简体中文Español日本語
桁区切り小数は 2 桁まで、末尾の 0 は省く
固定金額と比較する列は小数をそろえる
短縮狭い場所で。正確な値はホバーで

列にそろう数字

等幅数字を右揃えに。上下の向きは矢印で伝えます。

原則:等幅の数字
注文金額増減
#1042
#1043
#1044
#1045

意味は矢印で伝え、色は市場に合わせます。

相対時間とタイムゾーン

最近のものは言葉で、古いものは日付で。必要ならタイムゾーンを明記。

  • English
  • 简体中文
  • Español
  • 日本語
ローンチ会議

あなたの時刻

  • シンガポール
  • 東京
  • マドリード
  • ニューヨーク

マスキング

3 段階。マスクはサーバーで。

氏名
山**子
電話
090****5678
メール
j***@mail.com
カード
•••• 4242
身分証番号
12******9012

隠す部分はブラウザに届きません。表示するには再確認し、記録を残します。

空の値と読み込み

不明は「—」、読み込み中はバー、本当にゼロのときだけ 0。

売上
注文
コンバージョン
売上—注文—コンバージョン—
良い 不明は「—」。本当にゼロのときだけ 0。
売上NaN注文undefinedコンバージョン$0.00
避ける 生の値が漏れる:NaN、undefined、偽の 0。

ヘルパー

依存のない 1 つのモジュール。すべてのプランに specs/format.js として入ります。

// LayQ format: every value on screen goes through here (specs/design.md, "Data formats"). Only Intl.
// A missing or unreadable value gives EMPTY, never NaN or undefined.
export const EMPTY = '—'

const missing = (v) => v == null || v === '' || (typeof v === 'number' && !Number.isFinite(v))
const toDate = (v) => (missing(v) || isNaN(new Date(v)) ? null : new Date(v))
const num = (v, locale, o) => (missing(v) ? EMPTY : new Intl.NumberFormat(locale, o).format(v))
const dt = (v, locale, o) => (toDate(v) ? new Intl.DateTimeFormat(locale, o).format(toDate(v)) : EMPTY)
const cycle = (hour12) => (hour12 ? 'h12' : 'h23')

export const number = (v, locale, { decimals = 2, fixed } = {}) => num(v, locale, { maximumFractionDigits: decimals, minimumFractionDigits: fixed ? decimals : 0 })
export const compact = (v, locale) => num(v, locale, { notation: 'compact', maximumFractionDigits: 1 })
export const percent = (ratio, locale) => num(ratio, locale, { style: 'percent', maximumFractionDigits: 1 })

// `direction` picks the colour, which depends on the market.
export function change(ratio, locale) {
  if (missing(ratio)) return { text: EMPTY, direction: 'none' }
  const step = Math.round(ratio * 1000)
  const direction = step > 0 ? 'up' : step < 0 ? 'down' : 'flat'
  return { text: { up: '▲ ', down: '▼ ', flat: '' }[direction] + num(ratio, locale, { style: 'percent', maximumFractionDigits: 1, signDisplay: 'exceptZero' }), direction }
}

// `minor`: in cents. `display`: 'symbol' or 'code'.
export function money(amount, currency, locale, { minor, display = 'symbol', compact } = {}) {
  if (missing(amount) || !currency) return EMPTY
  const digits = new Intl.NumberFormat('en', { style: 'currency', currency }).resolvedOptions().maximumFractionDigits
  const o = { style: 'currency', currency, currencyDisplay: display, ...(compact && { notation: 'compact', maximumFractionDigits: 1 }) }
  return num(minor ? amount / 10 ** digits : amount, locale, o)
}

// style: 'short' in tables, 'medium', 'long' in documents.
export const date = (v, locale, { style = 'medium', timeZone } = {}) => dt(v, locale, { dateStyle: style, timeZone })
export const time = (v, locale, { hour12, timeZone, zone } = {}) => dt(v, locale, { hour: '2-digit', minute: '2-digit', hourCycle: cycle(hour12), timeZone, timeZoneName: zone ? 'short' : undefined })
export function dateTime(v, locale, { style = 'medium', hour12, timeZone, zone } = {}) {
  const text = dt(v, locale, { dateStyle: style, timeStyle: 'short', hourCycle: cycle(hour12), timeZone })
  return zone && toDate(v) ? text + ' ' + new Intl.DateTimeFormat(locale, { timeZoneName: 'short', timeZone }).formatToParts(toDate(v)).at(-1).value : text
}
export const dateRange = (a, b, locale, { style = 'medium', timeZone } = {}) =>
  toDate(a) && toDate(b) ? new Intl.DateTimeFormat(locale, { dateStyle: style, timeZone }).formatRange(toDate(a), toDate(b)) : EMPTY

// [below this age in seconds, unit, seconds per unit]; past a week, the date.
export const relativeBands = [
  [60, 'now'],
  [3600, 'minute', 60],
  [86400, 'hour', 3600],
  [604800, 'day', 86400],
]
export function relative(v, locale, { now = Date.now() } = {}) {
  if (!toDate(v)) return EMPTY
  const s = (toDate(v) - now) / 1000
  const [, unit, size] = relativeBands.find(([below]) => Math.abs(s) < below) ?? []
  const words = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })
  return !unit ? date(v, locale) : size ? words.format(Math.trunc(s / size), unit) : words.format(0, 'second')
}

// 1h 5m; style 'clock' (1:05:09) for media and timers.
export function duration(seconds, locale, { style } = {}) {
  if (missing(seconds)) return EMPTY
  const all = Math.max(0, Math.round(seconds))
  const [h, m, s] = [Math.floor(all / 3600), Math.floor(all / 60) % 60, all % 60]
  const two = (n) => String(n).padStart(2, '0')
  if (style === 'clock') return (h ? h + ':' + two(m) : m) + ':' + two(s)
  const unit = (n, u) => num(n, locale, { style: 'unit', unit: u, unitDisplay: 'narrow' })
  return (h ? [unit(h, 'hour'), m && unit(m, 'minute')] : m ? [unit(m, 'minute'), s && unit(s, 'second')] : [unit(s, 'second')]).filter(Boolean).join(' ')
}

export function bytes(v, locale) {
  if (missing(v) || v < 0) return EMPTY
  if (v < 1000) return number(v, locale) + ' B'
  const step = Math.min(4, Math.floor(Math.log10(v) / 3))
  const n = v / 1000 ** step
  return num(n, locale, { style: 'unit', unit: [, 'kilobyte', 'megabyte', 'gigabyte', 'terabyte'][step], maximumFractionDigits: n < 10 ? 1 : 0 })
}