I have a state as value: 10.00
and once I update it with some operation and add it to a <Text>
the “.00” part gets trimmed off. If it was a value like 10.50, it’ll be displayed as 10.5
This is a issue as I want to display currency values. How to handle this?
Advertisement
Answer
Found the answer. To have the value with decimal values, use toFixed()
method.
Example:
JavaScript
x
4
1
var value = 10;
2
value = value.toFixed(2);
3
this.setState({subTotal: value});
4
The output would be: 10.00