首页 > 解决方案 > 如何用符号格式化土耳其里拉?

问题描述

我试图用语言环境来做,但它只显示为文本并且符号没有出现。我正在使用 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

标签: javaformattinglocale

解决方案


没问题

我将您的代码分成多行以便于调试。

当我在 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


推荐阅读