看板 java 關於我們 聯絡資訊
其實可以很簡單的用 DecimalFormat 做出來,只是有點「不算限制的限制」 XD DecimalFormat df = new DecimalFormat(); df.setGroupingUsed(false); df.setMaximumFractionDigits(340); df.setMinimumIntegerDigits(1); df.setDecimalSeparatorAlwaysShown(false); System.out.println(df.format(319.129139128312d)); System.out.println(df.format(0.39138128192d)); System.out.println(df.format(0.00000000d)); System.out.println(df.format(12.00000000d)); System.out.println(df.format(-319.129139128312d)); System.out.println(df.format(-0.39138128192d)); System.out.println(df.format(-0.00000000d)); System.out.println(df.format(-12.00000000d)); Output: 319.129139128312 0.39138128192 0 12 -319.129139128312 -0.39138128192 -0 -12 那個「不算限制的限制」是最多只會出現小數後 340 位 要是真有人輸入超過小數後 340 位的數字... 那我也只有投降了 XD -- 很多人以為 所以我要 其實我是個 我是大學生 告訴大家 三十一歲的怪叔叔 ● ●/ ︿ ︿ /\ < ● ㄨ /\ ㄨ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 147.8.127.102