bootstrap-vue
Version:
BootstrapVue, with more than 85 custom components, over 45 plugins, several custom directives, and over 300 icons, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated W
20 lines (16 loc) • 713 B
JavaScript
// Number utilities
// Converts a value (string, number, etc) to an integer number
// Assumes radix base 10
export const toInteger = (value, defaultValue = NaN) => {
const integer = parseInt(value, 10)
return isNaN(integer) ? defaultValue : integer
}
// Converts a value (string, number, etc) to a number
export const toFloat = (value, defaultValue = NaN) => {
const float = parseFloat(value)
return isNaN(float) ? defaultValue : float
}
// Converts a value (string, number, etc) to a string
// representation with `precision` digits after the decimal
// Returns the string 'NaN' if the value cannot be converted
export const toFixed = (val, precision) => toFloat(val).toFixed(toInteger(precision, 0))