gpt4 book ai didi

javascript - 如何在 Angular js View 中返回整数值而不是科学值?

转载 作者:太空宇宙 更新时间:2023-11-04 15:42:22 24 4
gpt4 key购买 nike

我有这个函数可以从 dp(密度无关)转换为 px(像素):

$rootScope.dp2px = function(dp) {
if(!!dp) {
var px = window.devicePixelRatio * dp / 160;
return px.toPrecision(2);
} else {
return 0;
}
}

函数没有错误。但是当我想在 angularjs View 中使用该函数时,例如:

<h6 style="font-size:{{dp2px(2901.33)}}px !important; width:{{dp2px(17067)}}px !important;" ng-click="openPopoverGiftBox($event)">{{countergift}}</h6>

然后输出变成:

<h6 style="font-size:17px !important; width:1.0e+2px !important;" ng-click="openPopoverGiftBox($event)" class="ng-binding">4 Jam</h6>

如何让1.0e+2px的值始终为100px

有人可以帮助我吗?

最佳答案

How let the value of 1.0e+2px always 100px?

您可以使用 Number 函数来实现此目的:

var sc = "1.0e+2";
console.log(Number(sc));

关于javascript - 如何在 Angular js View 中返回整数值而不是科学值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776267/

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