久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

DecimalFormat 可變組大小

DecimalFormat variable group size(DecimalFormat 可變組大小)
本文介紹了DecimalFormat 可變組大小的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在發(fā)布問題之前,我已經(jīng)對該主題進行了一些研究,但找不到答案.

I've researched the subject somewhat before posting the question, but I couldn't find the answer.

這是我想要做的:

輸入:一個長 7-8 個小數(shù)位的數(shù)字(無分數(shù)).

input: a number 7-8 decimal spaces long (no fractions).

輸出:X XXXXXX X",其中 X 是一個數(shù)字,必須存在.

output: "X XXXXXX X" where X is a digit, must be present.

示例:1234567 => 0 123456 7

example: 1234567 => 0 123456 7

我嘗試了什么:

DecimalFormatSymbols group = new DecimalFormatSymbols();  
group.setGroupingSeparator(' '); 
DecimalFormat idFormat = new DecimalFormat("0,000000,0", group);

但這會打印出類似0 1 2 3 4 5 6 7"的內(nèi)容:S 我做錯了什么?

But this prints something like "0 1 2 3 4 5 6 7" instead :S What am I doing wrong?

如果我這樣做,我可以打印我需要的東西:

I can print what I need if I do this:

DecimalFormatSymbols group = new DecimalFormatSymbols();  
group.setGroupingSeparator(' ');
group.setDecimalSeparator(' ');
DecimalFormat idFormat = new DecimalFormat("0,000000.0", group);

通過重新閱讀手冊,我意識到 DecimalFormat 沒有辦法打印可變長度組(幸運的是我只需要 2 個 - 所以我可以使用小數(shù)部分).但是你將如何正確"地做到這一點?是否可以在這里使用正則表達式/編寫我自己的函數(shù),或者是否有庫已經(jīng)這樣做了?

And from re-reading the manual, I realized that DecimalFormat doesn't have a way to print variable length groups (I'm lucky I only need 2 - so I can use fraction part). But how would you do this "properly"? Would it be OK to use regular expression here / write my own function, or are there libraries that do this already?

只是為了好玩,下面是基于正則表達式的方法:)

Just for kicks, below is the regex-based way of doing it :)

Random random = new Random();
System.out.println(
      String.valueOf(Math.round(random.nextDouble() * 1e8))
      .replaceAll("(.*)(\d{6})(\d)$", "$1 $2 $3")
      .replaceAll("^ ", "0 "));

推薦答案

我認為您不能為此使用 DecimalFormat 分組分隔符.來自 Javadoc:

I don't think you can use the DecimalFormat grouping separator for this. From the Javadoc:

如果您提供具有多個分組字符的模式,則最后一個和整數(shù)末尾之間的間隔就是所使用的間隔.所以 "#,##,###,####" == "######,####" == "##,####,####".

If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".

這篇關于DecimalFormat 可變組大小的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 国产精品自产av一区二区三区 | 九九热国产精品视频 | 亚洲色图第一页 | 日韩在线免费 | 一区二区在线免费观看 | 成人午夜性成交 | 男女羞羞视频在线观看 | 日本aaa视频 | 欧美激情精品久久久久 | 99热精品在线观看 | 久久久久国产精品www | 国产精品资源在线 | 欧美日韩在线播放 | 成人在线观看中文字幕 | 国产美女一区二区 | 亚洲视频在线观看 | 亚洲欧美日韩精品久久亚洲区 | 国产高潮好爽受不了了夜夜做 | 麻豆久久久9性大片 | 亚洲国产情侣自拍 | 国产亚洲一区二区三区 | 亚洲国产精品va在线看黑人 | 亚洲一区二区三区国产 | 久久狠狠| 激情欧美日韩一区二区 | 久久久久久91 | 国产在线一区二区 | 五月婷六月丁香 | 欧美精品一区二区三区在线 | 日韩三级电影一区二区 | 农村妇女毛片精品久久久 | 欧美精品一区二区在线观看 | 99视频在线播放 | 日韩精品极品视频在线观看免费 | 欧美aⅴ片 | 亚洲精品二三区 | 一区二区免费在线视频 | 精品国产18久久久久久二百 | 久久国产视频网 | 国产精品视频免费播放 | 亚洲一区二区三区 |