【发布时间】:2021-12-30 12:37:54
【问题描述】:
我在 react-native 中有这段代码
<Grid item xs={12} sm={12} md={12} lg={12} style={{textAlign:isRTL==='rtl'?'right':'left'}}>
<Typography color={'primary'} style={{fontSize:30}}>
{t('total')} - {settings?settings.symbol:null} {estimatedata.estimate ? estimatedata.estimate.estimateFare : null}
</Typography>
</Grid>
我想要做的是,我想输出一个不带小数的公平估计,并将其四舍五入到最接近的 10s
例如,如果价格首先是 1458.10,我希望去掉 2 位小数,并且我希望新价格是 1460。
因此,输入.fixed{0} 会为我破坏代码。
请问我该怎么做?
在代码的另一部分。作为第二个问题,我能够完成这项工作parseFloat(estimate.estimateFare).toFixed(0),但问题是尽管小数消失了,但它并没有按照我想要的方式进行四舍五入。
1564 到 1560 或 1780 到 1800
【问题讨论】:
-
.fixed{0}- 这与 JS 或 JSX 语法一样无效,因此它不起作用也就不足为奇了。
标签: reactjs parsefloat