How to conver SALES VALUE from 9999.99 to 9.999,99

ぃ、小莉子 提交于 2020-01-25 04:02:07

问题


Currently looking for an easy way to convert 99999.99 to 9.999,99 format:

This is what I have currently:

CREATE TEMP FUNCTION FORMAT_DE_VALUE(number FLOAT64)
RETURNS STRING
LANGUAGE js 
AS """
return number.toFixed(2) + ' €';
""";

TRY 1:

  • return number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' });

  • NO Success - number stays the same


回答1:


If you can't use regex, then you can try something like this that uses QoL Array methods.

The idea is to start in reverse and to have each item of your list as a string containing a maximum of three digits.

const [whole, dec] = 9999999.99
.toFixed(2)
.split(".");

const res = whole
.split("")
.reverse()
.reduce((acc,cur)=>{
  if(acc[0].length === 3){
    acc.unshift("");
  }
  acc[0] = cur + acc[0];
  return acc;
}, [""])
.join(".")
.concat("," + dec)

console.log(res);


来源:https://stackoverflow.com/questions/58487076/how-to-conver-sales-value-from-9999-99-to-9-999-99

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!