java.text.DecimalFormat類十進(jìn)制格式化
更新時(shí)間:2018年03月01日 13:46:17 作者:jwdstef
這篇文章主要為大家詳細(xì)介紹了java.text.DecimalFormat類十進(jìn)制格式化的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
java.text.DecimalFormat類十進(jìn)制格式化的具體代碼,供大家參考,具體內(nèi)容如下
import java.text.DecimalFormat; class FormatDemo{ public void format1(String pattern,double value){ // 聲明一個(gè)DecimalFormat對(duì)象 DecimalFormat df = new DecimalFormat(pattern); String str = df.format(value); System.out.println("使用" + pattern + "樣式格式化:" + value + " 得到:"+ str); } } public class Test{ public static void main(String args[]){ FormatDemo fd = new FormatDemo(); fd.format1("###,###.###", 111222.34567); //前邊不夠補(bǔ)0 后邊多余四舍五入 不夠補(bǔ)0 fd.format1("000,000.000", 11222.34567); fd.format1("###,###.###¥", 111222.34567); fd.format1("000,000.000¥", 11222.34567); //百分之多少 fd.format1("##.###%", 0.345678); //百分之多少 fd.format1("00.###%", 0.0345678); //千分之多少 fd.format1("###.###/u2030", 0.345678); //指數(shù)形式 DecimalFormat df1 = new DecimalFormat(); //用下這個(gè)東西applypattern df1.applyPattern("0.000E0000"); System.out.println(df1.format(111222.34567)); } }
程序運(yùn)行結(jié)果:
使用###,###.###樣式格式化:111222.34567 得到:111,222.346 使用000,000.000樣式格式化:11222.34567 得到:011,222.346 使用###,###.###¥樣式格式化:111222.34567 得到:111,222.346¥ 使用000,000.000¥樣式格式化:11222.34567 得到:011,222.346¥ 使用##.###%樣式格式化:0.345678 得到:34.568% 使用00.###%樣式格式化:0.0345678 得到:03.457% 使用###.###‰樣式格式化:0.345678 得到:345.678‰ 1.112E0005
DecimalFormat格式化模板
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot測(cè)試類注入Bean失敗的原因及分析
SpringBoot 2.2版本前后測(cè)試類有所變化,2.2版本之后使用JUnit 5,導(dǎo)入注解@SpringBootTest和@Test來(lái)自junit.jupiter.api包;而2.2版本之前使用JUnit 4,需要額外導(dǎo)入@RunWith注解來(lái)自junit.runner包,無(wú)論哪個(gè)版本,都需確保測(cè)試類和啟動(dòng)類的包名一致2024-09-09解析SpringBoot項(xiàng)目開(kāi)發(fā)之Gzip壓縮過(guò)程
這篇文章主要介紹了SpringBoot項(xiàng)目開(kāi)發(fā)之Gzip壓縮過(guò)程,本文給大家分享幾種Gzip壓縮方式,通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07Java中EasyExcel使用自定義Converter處理方法詳解
EasyExcel自定義Converter是指在使用EasyExcel進(jìn)行Excel讀寫(xiě)操作時(shí),可以自定義轉(zhuǎn)換器來(lái)處理一些不支持的數(shù)據(jù)類型,這篇文章主要給大家介紹了關(guān)于Java中EasyExcel使用自定義Converter處理的相關(guān)資料,需要的朋友可以參考下2024-08-08Swagger3.0 整合spring boot2.7x避免swagger2.0與boot2.7沖突
這篇文章主要介紹了Swagger3.0 整合spring boot2.7x避免swagger2.0與boot2.7沖突問(wèn)題,通過(guò)注釋掉2.0引入的倆包,直接引入3.0,文中結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2023-10-10