MCPcopy Create free account
hub / github.com/caesarHQ/textSQL / formatNumber

Function formatNumber

client/censusGPT/src/components/table.js:19–54  ·  view source on GitHub ↗
(value, col)

Source from the content-addressed store, hash-verified

17}
18
19const formatNumber = (value, col) => {
20 if (value === null) {
21 return 'Unknown'
22 }
23 // Format the number to have commas
24 if (col == 'zip_code') {
25 // Don't format the zip code
26 return value
27 }
28 if (col.includes('date')) {
29 // Don't format the date
30 return value
31 }
32 if (col.includes('time')) {
33 // Don't format the time
34 return value
35 }
36 if (col.includes('percentage')) {
37 let newValue = value.toString()
38 if (newValue.includes('.')) {
39 // Round to 2 decimal places
40 newValue = newValue.slice(0, newValue.indexOf('.') + 3)
41 } else {
42 // Add commas if no decimal places
43 newValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
44 }
45 newValue = newValue + '%' // Add the percentage sign
46 return newValue
47 }
48
49 if (!value.toString().includes('.')) {
50 return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
51 }
52
53 return value
54}
55
56/**
57 * Generates the table header

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected