E
E
Eugene Zalivadnyi2015-10-25 15:47:22
JavaScript
Eugene Zalivadnyi, 2015-10-25 15:47:22

How to round a number to tenths in Angular?

A number is fed to the function, divided by the number of users entered, and substituted into another field.
For example, we give 1570, divide by 2 people, we get 785.
How to round up so that 785 becomes 790?
I'm trying to do it through round, Math.round. Doesn't round, but doesn't throw errors either.
Why is this code not working?

$scope.onUserAmountChange = function($summ) {
            $scope.model.price = Math.round(($summ / $scope.model.amount_users), -1);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2015-10-25
@agnamanshamansky

Math.round(785/10)*10
Or make a function

function round(n, f) {
    f = Math.pow(10, -f);
    return Math.round(n / f) * f;
}
round(785, -1) // 790

And these are not tenths, but dozens.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question