| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /**
- * Integer cents → display format utilities
- * All backend prices now stored as Integer cents (1元 = 100)
- * All backend rates stored as Integer bps (100% = 10000)
- * All backend scores stored as Integer percentile (5.00 = 500)
- */
- /**
- * Format cents to yuan string (no symbol)
- * 9900 → '99.00'
- */
- export function formatPrice (cents) {
- if (cents === null || cents === undefined) return '0.00'
- return (Number(cents) / 100).toFixed(2)
- }
- /**
- * Format cents to yuan with ¥ symbol
- * 9900 → '¥99.00'
- */
- export function formatPriceWithSymbol (cents) {
- return '¥' + formatPrice(cents)
- }
- /**
- * Format bps to percentage string
- * 235 → '2.35%' 1000 → '10.00%'
- */
- export function formatRate (bps) {
- if (bps === null || bps === undefined) return '0.00%'
- return (Number(bps) / 100).toFixed(2) + '%'
- }
- /**
- * Format percentile score to decimal display
- * 500 → '5.00' 435 → '4.35'
- */
- export function formatScore (percentile) {
- if (percentile === null || percentile === undefined) return '0.00'
- return (Number(percentile) / 100).toFixed(2)
- }
- /**
- * Format ISO datetime string to Chinese style: 'yyyy-MM-dd HH:mm:ss' -> 'yyyy年MM月dd日 HH:mm:ss'
- * Handles: null/undefined -> '-', already-formatted strings -> idempotent passthrough
- */
- export function formatDateTime (t) {
- if (t === null || t === undefined || t === '') return '-'
- const s = String(t).replace('T', ' ').trim()
- const m = s.match(/^(\d{4})-(\d{2})-(\d{2})(.*)$/)
- if (!m) return s
- const timePart = m[4] ? ' ' + m[4].trim().substring(0, 8) : ''
- return m[1] + '年' + m[2] + '月' + m[3] + '日' + timePart
- }
- /**
- * Format ISO datetime string to Chinese date only: 'yyyy-MM-dd HH:mm:ss' -> 'yyyy年MM月dd日'
- */
- export function formatDate (t) {
- if (t === null || t === undefined || t === '') return '-'
- const dt = formatDateTime(t)
- if (dt === '-') return '-'
- return dt.indexOf(' ') >= 0 ? dt.substring(0, dt.indexOf(' ')) : dt
- }
|