0
In my code, I receive a JSON with a value (Example: 6647), and I would like to round it to just 1 decimal place.
In the code, I take Json’s content by the call:
render(){
return(
<div className="container">
<div className="row">
<div className="col-md-12 col-lg-6 col-xl-3">
<div className = "row">
<div className = "info-box">
<span className = "info-box-icon logo-View">
<i className = "fa fa-tasks"> </i> </span>
<div className = "info-box-content">
<span className = "info-box-number">{this.state.data.pageViews}</span>
<span className = "info-box-text"> Page Views </span>
</div>
</div>
</div></div>
</div>
);
}
And the class:
componentDidMount(){
let URL = 'algumaURL'
fetch(URL)
.then(function(response) {
let data = response.json()
return data;
})
.then((json) => {
console.log('parsed json', json)
this.setState({data : json});
})
.catch(function(ex) {
console.log('parsing failed', ex)
})
}
JSON:
{"pageViews":13184}
Pageviews value is randomized at each page refresh.
How many decimal places by default, two
66,47
or three6,647
?– rubStackOverflow
Round to 1 decimal place, 6,647 -> 6,6
– Henrique Hermes