简体   繁体   English

如何用符号格式化土耳其里拉?

[英]How can i format turkish lira with symbol?

I tried to do it with the locale, but it only appears as text and the symbol doesn't come out.我试图用语言环境来做,但它只显示为文本,符号不出来。 I am using JAVA 14 SDK.我正在使用 JAVA 14 SDK。

Code I tried:我试过的代码:

  Locale tr = new Locale("tr", "TR");
  BigDecimal points = new BigDecimal(175678.64);
  System.out.println(NumberFormat.getCurrencyInstance(tr).format(points));

Output:输出:

175.678,64 TL

I want:我想要:

₺175.678,64

No problem没问题

I broke out your code to multiple lines for easier debugging.我将您的代码分成多行以便于调试。

When I run it in the IdeOne.com site, I get your desired output.当我在 IdeOne.com站点上运行它时,我得到了你想要的输出。

By the way, you should pass your input number as text (add quote marks).顺便说一下,您应该将输入的数字作为文本传递(添加引号)。 Otherwise you are defeating the purpose of using BigDecimal.否则,您就违背了使用 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 ) ;


    }
}

When run:运行时:

₺175.678,64 ₺175.678,64

Consider using the Currency class of java.util.Currency .考虑使用java.util.CurrencyCurrency类。 The Currency class has two methods getSymbol() and getSymbol(Locale locale) . Currency类有两个方法getSymbol()getSymbol(Locale locale) In your case you should use the second method with the locale parameter.在您的情况下,您应该使用带有locale参数的第二种方法。 This will return a String that represents the currency symbol for turkish lira.这将返回一个代表土耳其里拉货币符号的String

You can initialize your Currency object like this:您可以像这样初始化您的Currency对象:

Currency currency = Currency.getInstance(tr);

and

currency.getSymbol(tr);

will return the currency symbol as a String将货币符号作为String返回

In addition, you should know that the unidoce representation of turkish lira symbol as a char in Java is \₺此外,您应该知道,在 Java 中,土耳其里拉符号作为字符的 unidoce 表示是\₺

try this change 'Locale.CANADA' with your country尝试在您的国家/地区更改“Locale.CANADA”

NumberFormat format = NumberFormat.getCurrencyInstance(Locale.CANADA);
        String currency = format.format(number);
        System.out.println("Currency in Canada : " + currency);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法使用 Java PDFWriter 将₺(土耳其里拉)图标添加到文件中 - I can't add the ₺ (Turkish Lira) icon to the file with Java PDFWriter 如何使用RecognizerIntent强制使用土耳其语? - How can I use RecognizerIntent to force using Turkish? 如何在android中读取带有土耳其语字符的文本文件? - How can I read a text file in android with Turkish characters? 我如何将Java Regex用于土耳其语字符到UTF-8 - How I can use Java Regex for Turkish characters to UTF-8 如何在Android EditText中使用土耳其语字符? - How can I use Turkish characters in Android EditText? 如何使用逗号和欧元符号将双精度格式设置为某些格式 - How can I format a double to something using comma and euro symbol 输入金额且缺少土耳其里拉“ TL”图标时,JFormattedTextField不设置值 - JFormattedTextField doesn't set the value when amount entered and Turkish Lira “TL” icon missing 如何在java中将“i”与土耳其语匹配? - How do I match “i” with Turkish i in java? 如何在java中显示符号? - How can I display a symbol in java? 如何在Java中将unicode字符串转换为土耳其语? - How do I convert a unicode string to turkish in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM