decimal-behavior
A decimal-behavior element that provides ceil, round, floor, format and decimalAdjustemnt methods. Decimal adjustment of a number implementation is taken from Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round.
[ This description is mirrored from README.md at github.com/Protoss78/decimal-behavior on 2019-05-10 ]
decimal-behavior
A decimal-behavior element that provides ceil, round, floor, format and decimalAdjustemnt methods. Decimal adjustment of a number implementation is taken from Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round.
API documentation and live demo can be found on the component page
Installation
Install using bower
bower i decimal-behavior -S
Import the behavior
<link rel="import" href="../bower_components/decimal-behavior/decimal-behavior.html">
Inlude the behavior in your web component
behaviors: [DecimalBehavior]
Example
<dom-module id="x-decimal-behavior">
<template>
<style>
:host {
display: inline-block;
}
</style>
<h1>decimal-behavior</h1>
<div>round: [[formatNumber(3.125, 2)]]</div>
<div>floor: [[formatNumber(3.1415, 3, 'floor')]]</div>
<div>ceil : [[formatNumber(3.14151, 4, 'ceil')]]</div>
</template>
<script>
Polymer({
is: 'x-decimal-behavior',
behaviors: [DecimalBehavior]
});
</script>
</dom-module>
<x-decimal-behavior></x-decimal-behavior>
Methods
round(value, exp)
Decimal adjustment of a number using the round method.
- value: The number to be adjusted
- exp: The exponent (the 10 logarithm of the adjustment base). -1 = round to 1 decimal
floor(value, exp)
Decimal adjustment of a number using the floor method.
- value: The number to be adjusted
- exp: The exponent (the 10 logarithm of the adjustment base). -1 = round to 1 decimal
ceil(value, exp)
Decimal adjustment of a number using the ceil method.
- value: The number to be adjusted
- exp: The exponent (the 10 logarithm of the adjustment base). -1 = round to 1 decimal
formatNumber(value, decimals, type)
Adjusts and formats the passed value to the specified number of decimals using the passed adjustment type. The toFixed function is used to cut off the String representation.
- value: The number to be adjusted
- decimals: The number of decimals (is converted into an exponent). Example 1 = 1 decimal position
- type: The adjustment type: round, floor or ceil. round is set as default.
decimalAdjust(type, value, exp)
Decimal adjustment of a number. Original implementation from Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
- type: The adjustment type: round, floor or ceil
- value: The number to be adjusted
- exp: The exponent (the 10 logarithm of the adjustment base). -1 = round to 1 decimal
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Dependencies
- polymer#Polymer/polymer#^1.2.0
- Released
- 2016-04-29
- Maturity
- IMPORTED
- License
- Other
Compatibility
- Framework
- Polymer 1.0+
- Polymer 2.0+ in 1.0.0
- Browser
- Browser Independent
decimal-behavior - Vaadin Add-on Directory
A decimal-behavior element that provides ceil, round, floor, format and decimalAdjustemnt methods. Decimal adjustment of a number implementation is taken from Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round.decimal-behavior
Documentation
Online Demo
GitHub Homepage
Issue tracker
License
decimal-behavior version 0.0.1
### Dependencies
* polymer#Polymer/polymer#^1.2.0
decimal-behavior version 0.0.2
### Dependencies
* polymer#Polymer/polymer#^1.2.0
decimal-behavior version 0.0.3
### Dependencies
* polymer#Polymer/polymer#^1.2.0
decimal-behavior version 1.0.0
### Dependencies
* polymer#Polymer/polymer#1.9 - 2