【发布时间】:2019-11-25 00:08:11
【问题描述】:
使用打字稿,将 JSON 值转换为百分比的最佳方法是什么?
JSON
{
"outer_attribute": {
"brands": [
{
"brand_names": "brand6",
"Vertical": "Automotive",
"customer_visit_ratio": "0.03935382863419896"
},
{
"brand_names": "brand5",
"Vertical": "Automotive",
"customer_visit_ratio": "0.00935382863419896"
},
{
"brand_names": "brand12",
"Vertical": "Automotive",
"customer_visit_ratio": "0.30935382863419896"
}
]
}
}
我需要将“customer_visit_ratio”的值转换为百分比值。尝试了 .map 但没有用。
【问题讨论】:
-
可以工作..您尝试了什么?请注意,这些是字符串..您需要先转换为浮点数..
-
stackoverflow.com/questions/35474069/… 试过这个@MikeOne
-
@Abhijeetc50 在下面查看我的更新答案
标签: json angular typescript