我试图用语言环境来做,但它只显示为文本,符号不出来。我正在使用 JAVA 14 SDK。
我试过的代码:
Locale tr = new Locale("tr", "TR");
BigDecimal points = new BigDecimal(175678.64);
System.out.println(NumberFormat.getCurrencyInstance(tr).format(points));
输出:
175.678,64 TL
我想要:
₺175.678,64
最佳答案
没问题
我将您的代码分成多行以便于调试。
当我run it in the IdeOne.com网站,我得到了你想要的输出。
顺便说一下,您应该将输入的数字作为文本传递(添加引号)。否则,您就违背了使用 BigDecimal 的目的。
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.* ;
import java.text.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Locale locale = new Locale("tr", "TR");
BigDecimal points = new BigDecimal( "175678.64" ) ;
NumberFormat f = NumberFormat.getCurrencyInstance( locale ) ;
String output = f.format( points ) ;
System.out.println( output ) ;
}
}
运行时:
₺175.678,64
关于java - 如何用符号格式化土耳其里拉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61367170/