-3

Here, my problem is how to use the floor function in this code because I want to upper value for display like if value is 5.4 convert to 6 and 5.3 convert to 6.

How to value get in upper level 0.83 to 1 in below example

<!DOCTYPE html>
<html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <body>
        <div ng-app="">
            <h1>Hello {{5/6}}</h1>
        </div>
    </body>
</html>
M0nst3R
  • 5,186
  • 1
  • 23
  • 36
Axit Sompura
  • 75
  • 1
  • 3
  • 12
  • 1
    *"5.3 convert to 6"* - this is not a `floor` function, this is more `ceil` function – Stanislav Kvitash Nov 09 '17 at 10:12
  • 1
    I guess its more of `Math.ceil` function – Rajesh Nov 09 '17 at 10:13
  • How did it get that this question is so "upvoted"? – Stanislav Kvitash Nov 09 '17 at 10:13
  • see here in this example for php floor function work same as my requirements-"); echo(floor(0.40) . "
    "); echo(floor(5) . "
    "); echo(floor(5.1) . "
    "); echo(floor(-5.1) . "
    "); echo(floor(-5.9)); ?>
    –  Nov 09 '17 at 10:17
  • @axitsompura 1) We are talking about `javascript`, not `php`; 2) Do you have multiple accounts here? – Stanislav Kvitash Nov 09 '17 at 10:21
  • No , i know this question is for angular js but i suggest only this example –  Nov 09 '17 at 10:26
  • create a filter `.filter('roundup', function () { return function (value) { return Math.ceil(value); }; })` like this. and in your html do this `

    Hello {{ 5/6 | roundup }}

    ` it will handle your view.
    – abhit Nov 09 '17 at 10:29

2 Answers2

-1

Hi in this case it's better to use the Math.ceil() function which gives the ceiling value.

First u have to inject it to u're scope.U can use below code segment for that

$scope.Math = window.Math;

And then use the Math.celi() function

-1

try this code its definately works for you

var app = angular.module('filters', []);

app.controller('currencies', function($scope){
  $scope.defaultNumber = 60.99;
  $scope.defaultNumberWhole = 59;
})
body {
  background: #232323;
}

.credits {
  margin: 15px 0px;
}

.panel {
  margin: 15px 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<div class="container">
  <div class="row">
    <div class="col-lg-6 col-lg-offset-3">
      <div ng-app="filters">
        <div ng-controller="currencies">
          <div class="panel panel-default">
             <div class="panel-body">
               <h4 class="text-center">AngularJS Filter - Decimal Point Control (Angular 1.3+)</h4>
               <p><strong>Original:</strong></p>
               <p>{{defaultNumber}}</p>
               <p><strong>Currency Decimal Control:</strong></p>
               <p>{{defaultNumber | currency:'£':0}}</p>
            </div>
          </div>
      </div>
    </div>
  </div>
</div>
Nikul Khatik
  • 102
  • 2
  • 11