Document how to use formatNumber in JS and Vue

Background

See gitlab-org/frontend/rfcs#73 (closed)

TL;DR languages use different ways to show numbers, for example English uses commas as decimal separators (,), while Spanish uses periods (.). Our Vue UI often ignores this!

What does this MR do?

As described in the documentation this change enables as easily format numbers in all of our Vue templates:

  • In Vue templates
<script>
import { formatNumber } from '~/locale';

export default {
  //...
  methods: {
    // ...
    formatNumber,
  },
}
</script>
<template>
<div class="my-number">
  {{ formatNumber(10000) }} <!-- 10,000 -->
</div>
<div class="my-percent">
  {{ formatNumber(0.5,  { style: 'percent' }) }} <!-- 50% -->
</div>
</template>

It additionally documents formatNumber as the favored way to display numbers:

  • In JavaScript
import { formatNumber } from '~/locale';

// Assuming "User Preferences > Language" is set to "English":

const tenThousand = formatNumber(10000); // "10,000" (uses comma as decimal symbol in English locale)
const fiftyPercent = formatNumber(0.5, { style: 'percent' }) // "50%" (other options are passed to toLocaleString)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Miguel Rincon

Merge request reports

Loading