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)189999189,999188999.50188,999.5040.004040.5040.50