https://github.com/protoss78/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.
https://github.com/protoss78/decimal-behavior
behavior ceil decimal decimal-behavior floor round
Last synced: 3 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/protoss78/decimal-behavior
- Owner: Protoss78
- Created: 2016-02-28T17:16:35.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-30T18:39:32.000Z (about 8 years ago)
- Last Synced: 2025-02-24T18:04:45.317Z (3 months ago)
- Topics: behavior, ceil, decimal, decimal-behavior, floor, round
- Language: HTML
- Size: 11.3 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
[](https://www.webcomponents.org/element/Protoss78/decimal-behavior)
# 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 bowerbower i decimal-behavior -S
Import the behavior
Inlude the behavior in your web component
behaviors: [DecimalBehavior]
## Example
```html
:host {
display: inline-block;
}
decimal-behavior
round: [[formatNumber(3.125, 2)]]
floor: [[formatNumber(3.1415, 3, 'floor')]]
ceil : [[formatNumber(3.14151, 4, 'ceil')]]
Polymer({
is: 'x-decimal-behavior',
behaviors: [DecimalBehavior]
});
```
## 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