java - 从 NumberFormat 格式中删除货币字符()

标签 java groovy formatting

<分区>

我试图在使用 NumberFormat 格式化货币后删除货币字符

import java.text.NumberFormat;

BigDecimal currencyAmount = new BigDecimal(9876543.21)
def currentLocale = Locale.US
def currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);

println "formatted currency = "+currencyFormatter.format(currencyAmount)

这会打印 $9,876,543.21 但我不想在格式化货币中使用 $ 或任何货币字符。有办法吗?

最佳答案

常规解决方案:

import java.text.NumberFormat

def currencyAmount = 9876543.21 //Default is BigDecimal
def currencyFormatter = NumberFormat.getInstance( Locale.US )

assert currencyFormatter.format( currencyAmount ) == "9,876,543.21"

如果不需要货币,则不需要 getCurrencyInstance()

关于java - 从 NumberFormat 格式中删除货币字符(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22998260/

相关文章:

Java:WatchService:File.Lastmodified 返回 0

java - 即使使用 JDK 8,Cytoscape 3.7.2 也无法安装在 Macos 10.15.3 上

java - Gradle Groovy 插件似乎删除了已编译的 Java 类

java - 有没有办法在groovy中自动设置字符串中的Windows路径?

grails - 不能对具有JSON对象的类使用不可变注释

java - 设置工具栏小部件标题时出现空指针异常

java - 使用 Spring 反序列化请求时如何处理动态 JSON 值类型?

python - 在映射理解范围内禁用字典表达式的Black格式化

java - 通过添加 '.' 、 ',' 、修剪(不四舍五入)使双倍可读,因此只有最后 2 位数字可能?

选定格式的 MySQL str_to_date 转换