gpt4 book ai didi

javascript - 如何在javascript中将stringyfied数组值转换为float

转载 作者:行者123 更新时间:2023-11-28 12:18:33 26 4
gpt4 key购买 nike

我使用data_str = JSON.stringify(data); 转换为字符串。 json 中的数据是

[{"temperSensorData":"28.489084691371996","temperSensorUnit":"celsius","timestamp":"1493270171424","timestamp2":"1493270171454","timestamp3":"1493270171454","val":"0"},{"temperSensorData":"28.48908469137112","temperSensorUnit":"celsius","timestamp":"1493270171426","timestamp2":"1493270171522","timestamp3":"1493270171523","val":"1"},{"temperSensorData":"28.489084691371186","temperSensorUnit":"celsius","timestamp":"1493270171426","timestamp2":"1493270171523","timestamp3":"1493270171524","val":"2"},{"temperSensorData":"28.489084691371595","temperSensorUnit":"celsius","timestamp":"1493270171426","timestamp2":"1493270171524","timestamp3":"1493270171525","val":"3"},{"temperSensorData":"28.48908469137168","temperSensorUnit":"celsius","timestamp":"1493270171428","timestamp2":"1493270171529","timestamp3":"1493270171529","val":"4"},{"temperSensorData":"28.489084691371684","temperSensorUnit":"celsius","timestamp":"1493270171428","timestamp2":"1493270171529","timestamp3":"1493270171529","val":"5"},{"temperSensorData":"28.489084691371357","temperSensorUnit":"celsius","timestamp":"1493270171429","timestamp2":"1493270171530","timestamp3":"1493270171531","val":"6"},{"temperSensorData":"28.489084691371144","temperSensorUnit":"celsius","timestamp":"1493270171429","timestamp2":"1493270171531","timestamp3":"1493270171532","val":"7"},{"temperSensorData":"28.48908469137181","temperSensorUnit":"celsius","timestamp":"1493270171431","timestamp2":"1493270171546","timestamp3":"1493270171546","val":"25"}]

现在我想获取时间戳值并执行一些数学运算。如何将其转换为浮点值?即使我使用了 parseInt(timestamp)Number(timestamp),它也不起作用并显示结果:NaN

最佳答案

尝试 parseFloat("28.489084691371996") 函数。它会对你有所帮助。

parseFloat("28.489084691371996")

如果您需要进一步帮助,请告诉我。

关于javascript - 如何在javascript中将stringyfied数组值转换为float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43730396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com