所以我有一些值应该打印为 toFixed(8),但有时会发生该值是带有文本的字符串,因此由于错误而忘记了后面的所有内容(在循环中)。
是否有可能使用 toFixed(8) 如果它可以打印 var 而没有 tofixed?
$.each(trades, function(_, obj) {
if (obj['sold'] == true) {
if (obj['enddate'] === undefined) {
count = 1
profit = obj['profit_percentage']
tradeList.add({
startdate: obj['datetime'],
if (typeof obj['buyprice'] === "number") {
buyprice: obj['buyprice'].toFixed(8)
}
else {
buyprice: obj['buyprice']
}
});
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>