const formattedPrice = (parseFloat(list.price) % 1 === 0
? parseInt(list.price)
: parseFloat(list.price).toFixed(2)
).toLocaleString("en-US");
Example Outputs
Input (list.price
)Output (formattedPrice
)189999
189,999
188999.50
188,999.50
40.00
40
40.50
40.50