java - 如何用符号格式化土耳其里拉?
问题描述
我试图用语言环境来做,但它只显示为文本并且符号没有出现。我正在使用 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
解决方案
没问题
我将您的代码分成多行以便于调试。
当我在 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
推荐阅读
- intellij-idea - 来自 shell 脚本的假 go 环境
- image - 反向图像搜索科学情节(图像文件),以识别原始文章
- google-apps-script - 复制谷歌表格后受保护单元格的问题
- reactjs - Webpack Uncaught ReferenceError: babelHelpers is not defined
- css - 如何在 Vuetify 中更改 v-text-field 的宽度?
- spring-boot - 从springboot发送soap请求时出现异常:无效的Content-Type:text/html。这是错误消息而不是 SOAP 响应吗?
- swift - Swift View 中的图像为空
- javascript - 显示适合 x 轴的点
- reactjs - 如果任何状态发生变化,为什么 React Hooks 会更新所有子组件?
- linux-kernel - 如何将树莓派上的 gpio 引脚与设备驱动程序中的设备树一起使用?