// 모의투자 표시용 순수 유틸 (서버·클라이언트 공용) — bp(basis point)·토큰 포맷 // bp = 만분율. 예: 1234bp = 12.34% import type { ChangeDirection } from '@/lib/utils/stock'; // bp 부호 방향 (수익률·손익 색 병행 표기용) export function bpDirection(bp: number|null|undefined): ChangeDirection { if (bp === null || bp === undefined || bp === 0) { return 'flat'; } return bp > 0 ? 'up' : 'down'; } // bp → % 문자열 (부호 포함). 예: 1234 → "+12.34%" export function formatBpPercent(bp: number|null|undefined): string { if (bp === null || bp === undefined) { return '—'; } const sign = bp > 0 ? '+' : ''; return `${sign}${(bp / 100).toFixed(2)}%`; } // bp → % 절대값 (부호 없이, 승률·MDD 등 방향 무의미한 지표용). 예: 6500 → "65.00%" export function formatBpAbs(bp: number|null|undefined): string { if (bp === null || bp === undefined) { return '—'; } return `${(Math.abs(bp) / 100).toFixed(2)}%`; } // 토큰 금액 (천 단위 구분 + "토큰" 단위) export function formatToken(value: number|null|undefined): string { if (value === null || value === undefined) { return '—'; } return `${value.toLocaleString('ko-KR')} 토큰`; } // 토큰 금액 (단위 없이 숫자만) export function formatTokenNumber(value: number|null|undefined): string { if (value === null || value === undefined) { return '—'; } return value.toLocaleString('ko-KR'); }