如何将SALES VALUE从9999.99转换为9.999,99 [英] How to conver SALES VALUE from 9999.99 to 9.999,99

查看:130
本文介绍了如何将SALES VALUE从9999.99转换为9.999,99的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在寻找一种将99999.99转换为9.999,99格式的简单方法:

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

这是我目前拥有的:

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

尝试1:

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

没有成功-数字保持不变

NO Success - number stays the same

推荐答案

如果不能使用正则表达式,则可以尝试使用QoL Array方法的类似方法.

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);

这篇关于如何将SALES VALUE从9999.99转换为9.999,99的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆