Example Analysis of decimal format of java.text.DecimalFormat Class
This article mainly introduces the java.text.DecimalFormat class decimal format example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Java.text.DecimalFormat class decimal format of the specific code for your reference, the specific content is as follows
Import java.text.DecimalFormat; class FormatDemo {public void format1 (String pattern,double value) {/ / declare a DecimalFormat object DecimalFormat df = new DecimalFormat (pattern); String str = df.format (value); System.out.println ("format using" + pattern + "style:" + value + "to get:" + str) }} public class Test {public static void main (String args []) {FormatDemo fd = new FormatDemo (); fd.format1 ("#, #. #", 111222.34567); / / not enough to round up 0 fd.format1 ("000000.000", 11222.34567); fd.format1 ("#, #. # ¥", 111222.34567) Fd.format1 ("000000.000 ¥", 11222.34567); / / how many per cent fd.format1 ("# #. #%", 0.345678); / / how many per cent fd.format1 ("00.percent percentage percentage", 0.0345678); / / how much fd.format1 ("#. # / u2030", 0.345678) / / exponential form DecimalFormat df1 = new DecimalFormat (); / / use this thing applypattern df1.applyPattern ("0"); System.out.println (df1.format (111222.34567));}}
The result of running the program:
Use #: 111222.34567 get: 111222.346 use 000000.000 style format: 11222.34567 get: 011222.346 use # # #. # ¥format: 111222.34567 get: 111222.346 ¥using 000000.000 ¥style format: 11222.34567 get: 011222.346 ¥using # #. #% style format: 0.345678 get: 34.568% format: 0.0345678 get: 03.457% use # ‰ style format: 0.345678 get: 345.678 ‰ 111200
DecimalFormat format template
Thank you for reading this article carefully. I hope the article "sample Analysis of java.text.DecimalFormat Decimal format" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!