I came up with this handy function that handles the conversion from dp (density independent) to px (pixels):
$rootScope.dp2px = function(dp) {
if(!!dp) {
var px = window.devicePixelRatio * dp / 160;
return px.toPrecision(2);
} else {
return 0;
}
}
The function works fine, but I encountered an issue when trying to use it in an angularjs view like this:
<h6 style="font-size:{{dp2px(2901.33)}}px !important; width:{{dp2px(17067)}}px !important;" ng-click="openPopoverGiftBox($event)">{{countergift}}</h6>
Instead of getting the expected output, I got:
<h6 style="font-size:17px !important; width:1.0e+2px !important;" ng-click="openPopoverGiftBox($event)" class="ng-binding">4 Jam</h6>
Is there a way to ensure that the value of 1.0e+2px
always shows as 100px
?
If anyone has a solution, please help me out!