js number format All In One

Posted xgqfrms

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js number format All In One相关的知识,希望对你有一定的参考价值。

js number format All In One 金融数据表示法 千分位符号 locales

js number format All In One

金融数据表示法

千分位符号

// 1,000,000

Number Format

const number = 123456.789;

console.log(new Intl.NumberFormat(\'de-DE\',  style: \'currency\', currency: \'EUR\' ).format(number));
// Expected output: "123.456,79 €"

// The Japanese yen doesn\'t use a minor unit
console.log(new Intl.NumberFormat(\'ja-JP\',  style: \'currency\', currency: \'JPY\' ).format(number));
// Expected output: "¥123,457"

// Limit to three significant digits
console.log(new Intl.NumberFormat(\'en-IN\',  maximumSignificantDigits: 3 ).format(number));
// Expected output: "1,23,000"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

new Intl.NumberFormat()
new Intl.NumberFormat(locales)
new Intl.NumberFormat(locales, options)

Intl.NumberFormat()
Intl.NumberFormat(locales)
Intl.NumberFormat(locales, options)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat

number.toLocaleString(locale, options);

https://simplelocalize.io/blog/posts/number-formatting-in-javascript/

demos

const number = 123456.789;

// ✅
// const rmb = new Intl.NumberFormat(\'zh-Hans-CN\', 
// ✅
// const rmb = new Intl.NumberFormat(\'zh-Hans\', 
// ✅
const rmb = new Intl.NumberFormat(\'zh-CN\', 
  style: \'currency\',
  // currency: \'RMB\', ❌
  currency: \'CNY\',
).format(number);

console.log(`RMB =`, rmb);
// Expected output: "¥123,457.789"

// RMB = ¥123,456.79 ❓❓❓

currency code

RMB

CNY

https://en.wikipedia.org/wiki/ISO_4217

const nf = new Intl.NumberFormat("en-US", 
  style: "currency",
  currency: "USD",
  maximumFractionDigits: 2,
  roundingIncrement: 5,
);

console.log(nf.format(11.29)); // "$11.30"
console.log(nf.format(11.25)); // "$11.25"
console.log(nf.format(11.22)); // "$11.20"

(

#Leetcode# 448. Find All Numbers Disappeared in an Array

https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/

 

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements of [1, n] inclusive that do not appear in this array.

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

Example:

Input:
[4,3,2,7,8,2,3,1]

Output:
[5,6]

代码:

class Solution {
public:
    vector<int> findDisappearedNumbers(vector<int>& nums) {
        int n = nums.size();
        int vis[100000] = {0};
        for(int i = 0; i < n; i ++) {
            vis[nums[i]] ++;
        }
        vector<int> ans;
        for(int i = 1; i <= n; i ++) {
            if(!vis[i]) ans.push_back(i);
        }
        return ans;
    }
};

  

以上是关于js number format All In One的主要内容,如果未能解决你的问题,请参考以下文章

#Leetcode# 448. Find All Numbers Disappeared in an Array

Find All Numbers Disappeared in an Array

Find All Numbers Disappeared in an Array

Find All Numbers Disappeared in an Array

Find All Numbers Disappeared in an Array

Find All Numbers Disappeared in an Array