How to use the @instructure/ui-i18n/lib/Decimal.parse function in @instructure/ui-i18n

To help you get started, we’ve selected a few @instructure/ui-i18n examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github instructure / instructure-ui / packages / ui-forms / src / components / NumberInput / index.js View on Github external
componentWillReceiveProps (nextProps, nextContext) {
    if (!this._input.value) return

    // If the locale or precision props change, update the input value accordingly
    const currentLocale = this.getLocale(this.props, this.context)
    const nextLocale = this.getLocale(nextProps, nextContext)
    const currentPrecision = this.getPrecision(this.props)
    const nextPrecision = this.getPrecision(nextProps)
    if (currentLocale === nextLocale && deepEqual(currentPrecision, nextPrecision)) return

    const decimalValue = Decimal.parse(this._input.value, currentLocale)
    if (decimalValue.isNaN()) return

    const formattedString = this.formatValue(decimalValue, nextLocale, nextPrecision)
    this.setState({ value: formattedString })
    nextProps.onChange(null, formattedString, this.normalizeValue(decimalValue, nextPrecision))
  }
github instructure / instructure-ui / packages / ui-forms / src / components / NumberInput / index.js View on Github external
applyStep = (dir) => {
    let d = Decimal.parse(this._input.value || '0', this.locale)
    if (this.step.isNaN()) return d

    if (!d.mod(this.step).equals(0)) {
      // case when value is between steps, so we snap to the next step
      const steps = d.div(this.step)

      if (dir > 0) {
        d = steps.floor().times(this.step)
      } else {
        d = steps.ceil().times(this.step)
      }
    }

    // then we add the step
    if (dir > 0) {
      d = d.plus(this.step)