Working on a Node web app with a MongoDB backend that consists of player statistics. In this specific instance, I'm saving a player stat as a decimal and converting it to a percentage on the webpage by multiplying the value by 100.
Here's the HTML / EJS template code I render on the page for a players 3 point percentage from one season:
<td><%= season.tp * 100 %></td>
Pass in that value and multiply it for a percentage that should be (for example) 39.8 and that is the case for most statistics; however, for one data point in particular it's 39.80000000004. This leads me to two questions:
- What could cause the number to format with these excessive (and nonexistent) decimal places? Is this something to do with how MongoDB stores number data?
- What can I do to prevent these decimal places from displaying?
I've seen other questions where the proposed solution is a JavaScript method that formats the decimal places, but changes the data type to a String. Since the goal would be to perform other aggregations with this data, I'd want to preserve the number type.
Thanks in advance for the help.