1

I have this function to convert 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 has no error. But when I want to use the function in angularjs view like:

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

Then the output become:

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

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

Anyone can help me?

2 Answers 2

1

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

You can use the Number function to achieve this:

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

Sign up to request clarification or add additional context in comments.

Comments

0

toPrecision is the problem, use toFixed

6 Comments

Sorry, still the same result 1.0e+2
can u check in console, whats ur function is returning?
Yes I've checked it.
toPrecision is the problem, use toFixed
Thanks for the answer. Number() function is the exactly solve my question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.