Download frontend/src/utils/format.js from AIVLAD/demo: direct link, hf CLI and curl.
- Browser
- Download file 691 Bytes
-
https://huggingface.co/spaces/AIVLAD/demo/resolve/main/frontend/src/utils/format.js
- Command line
-
hf download hf://spaces/AIVLAD/demo/frontend/src/utils/format.js
-
curl -L -o format.js https://huggingface.co/spaces/AIVLAD/demo/resolve/main/frontend/src/utils/format.js
691 Bytes
| /** | |
| * Format large numbers with K/M/B suffixes. | |
| * | |
| * @param {string|number} value - The number to format | |
| * @returns {string} Formatted number with suffix | |
| * | |
| * Examples: | |
| * formatNumber(1500) => "1.5K" | |
| * formatNumber(36309000) => "36.3M" | |
| * formatNumber(1200000000) => "1.2B" | |
| */ | |
| export function formatNumber(value) { | |
| const num = typeof value === 'string' ? parseFloat(value) : value | |
| if (isNaN(num)) { | |
| return '0' | |
| } | |
| if (num >= 1_000_000_000) { | |
| return (num / 1_000_000_000).toFixed(1) + 'B' | |
| } | |
| if (num >= 1_000_000) { | |
| return (num / 1_000_000).toFixed(1) + 'M' | |
| } | |
| if (num >= 1_000) { | |
| return (num / 1_000).toFixed(1) + 'K' | |
| } | |
| return num.toString() | |
| } | |