12 Aralık 2021 Pazar

CompactNumberFormat Sınıfı

Giriş
Şu satırı dahil ederiz
import java.text.CompactNumberFormat;
Açıklaması şöyle
CompactNumberFormat class is the subclass of NumberFormat class in java.text package, NumberFormat class formats a number in compact form. 

The NumberFormat Style, SHORT would display 1000 as 1K and 10000 as 10K. Whereas the Style LONG will display 1000 as 1 thousand and 10000 as 10 thousand.  
format metodu
Örnek
Şöyle yaparız
NumberFormat format = NumberFormat.getCompactNumberInstance(Locale.US,Style.SHORT);
System.out.println(format.format(1000);
//Output : 1K

format = NumberFormat.getCompactNumberInstance(Locale.US,Style.LONG);
System.out.println(format.format(1000);
//Output : 1 thousand
parse metodu
Örnek
Şöyle yaparız
NumberFormat format = NumberFormat.getCompactNumberInstance(Locale.US,Style.LONG);
System.out.println(format.parse("1 thousand"); //1_000 
System.out.println(format.parse("10 million"); //10_000_000


Hiç yorum yok:

Yorum Gönder