語言

NumberFormat 類別

定義

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

[Android.Runtime.Register("android/icu/text/NumberFormat", ApiSince=24, DoNotGenerateAcw=true)]
public abstract class NumberFormat : Android.Icu.Text.UFormat
[<Android.Runtime.Register("android/icu/text/NumberFormat", ApiSince=24, DoNotGenerateAcw=true)>]
type NumberFormat = class
    inherit UFormat
繼承
衍生
屬性

備註

<強力>[加護病房增強]</強重> 加護病房取代 java.text.NumberFormat. ICU特有的方法、領域及其他功能標示為「<強力>[重症監護室]</強力>」。

<強烈>重要:</強烈> 強烈建議新用戶看看是否 NumberFormatter 符合他們的使用情境。 雖然尚未被棄用,但這個類別 NumberFormat 僅提供給 java.text.NumberFormat 相容性。 <人資>

NumberFormat 是所有數字格式的抽象基底類別。 此類別提供格式化與解析數字的介面。 NumberFormat 同時提供判斷哪些地點有數字格式及其名稱的方法。

NumberFormat 幫助你格式化和解析任何地區的數字。 你的程式碼可以完全不受小數點、千分隔符,甚至特定小數位數字的限制,甚至數字格式是否為十進位,完全獨立。

要格式化當前 Locale 的數字,請使用工廠類別方法之一: <blockquote>

myString = NumberFormat.getInstance().format(myNumber);

</blockquote> 如果你要格式化多個數字,取得格式並多次使用會更有效率,這樣系統就不用多次取得當地語言和國家慣例的資訊。 <引用>

NumberFormat nf = NumberFormat.getInstance();
            for (int i = 0; i &lt; a.length; ++i) {
                output.println(nf.format(myNumber[i]) + "; ");
            }

</blockquote> 若要格式化不同地點的號碼,請在呼叫 中 getInstance指定。 <引用>

NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);

</blockquote> 你也可以用 a NumberFormat 來解析數字: <blockquote>

myNumber = nf.parse(myString);

</blockquote> 使用 getInstance 或 getNumberInstance 取得正常數字格式。 用來 getIntegerInstance 取得整數格式。 用 getCurrencyInstance 來取得貨幣編號格式。 並且用 getPercentInstance 來取得顯示百分比的格式。 部分工廠方法存在於 NumberFormat 的子類別中。 在此格式中,像0.53這樣的分數會顯示為53%。

從 ICU 4.2 開始,你可以透過參數傳遞 'style' 來取得正確的 instance()來取得正確的實例。 例如,使用 getInstance(...NUMBERSTYLE)要取得一般的數字格式,getInstance(...PERCENTSTYLE)要取得顯示百分比的格式,getInstance(...SCIENTIFICSTYLE)要取得顯示科學數字的格式,getInstance(...INTEGERSTYLE)要取得整數格式,getInstance(...CURRENCYSTYLE)以取得貨幣編號格式,其中貨幣以符號表示,例如「$3.00」。 getInstance(...ISOCURRENCYSTYLE)以取得貨幣編號格式,該格式中貨幣以 ISO 代碼表示,例如「USD3.00」。 getInstance(...PLURALCURRENCYSTYLE)以獲得貨幣編號格式,該貨幣以複數形式表示其全名,例如「3.00 US dollars」或「1.00 US dollar」。

你也可以用以下方法 setMinimumFractionDigits控制數字的顯示。 如果你想要更多對格式或解析的控制,或想給使用者更多控制權,可以嘗試將 NumberFormat 從工廠取得的方法投射成 DecimalFormat。 這對絕大多數地點都適用;記得把它放在 try 方塊裡,以防遇到異常的方塊。

NumberFormat 的設計使得有些控制項用於格式化,其他控制項則用於解析。 以下是這些控制方法的詳細說明,

setParseIntegerOnly : 僅影響解析,例如若為真,則「3456.78」 ->3456(並在「6」後離開解析位置)若為假,則「3456.78」→;3456.78(且在「8」後離開解析位置)這與格式無關。 如果你不想顯示小數點後面可能沒有數字,可以在 DecimalFormat 上使用 setDecimalSeparatorAlwaysShown 。

你也可以使用和parseformat方法的形式ParsePositionFieldPosition,讓你能:<ul><li> 逐步解析字串<片段 li> 對齊小數點及其他區域 </ul> 例如,你可以用兩種方式<對齊數字:ol><li> 如果你使用帶有空格的字型來對齊,你可以在格式中呼叫 ,FieldPosition 其中 field = INTEGER_FIELD。 輸出時, getEndIndex 將設定為整數最後一個字元與小數點之間的偏移量。 在字串前方加(desiredSpaceCount - getEndIndex)空格。

<如果你> 使用比例字型,不要用空格填充,而是從起點到 getEndIndex的像素來測量字串的寬度。 接著在繪製文字前,將筆移動 (desiredPixelWidth - widthToAlignmentPoint) 它也適用於沒有小數點,但可能在末尾加額外字元的情況,例如用負數括號表示「(12)」表示 -12。 </ol>

<h3>同步</h3>

數字格式通常不會同步。 建議為每個執行緒建立獨立格式實例。 若多個執行緒同時存取同一格式,必須在外部同步。

<h4>DecimalFormat</h4>

DecimalFormat 是 NumberFormat 的具體實作,而 NumberFormat API 本質上是 DecimalFormat API 的抽象。 欲了解更多關於此 API 的資訊,請參閱 DecimalFormat。

參見 DecimalFormat,請參見 java.text.ChoiceFormat

Java 文件 android.icu.text.NumberFormat。

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

建構函式

名稱 Description
NumberFormat()

空的建造器。

NumberFormat(IntPtr, JniHandleOwnership)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

欄位

名稱 Description
Accountingcurrencystyle
已淘汰.

<strong>[icu]</strong> Constant 用來指定以貨幣符號表示貨幣的格式,例如:「($3.

Cashcurrencystyle
已淘汰.

<strong>[icu]</strong> Constant 用來指定貨幣現金格式,使用貨幣 ISO 代碼來表示貨幣,例如:「NT$3」而非「NT$3」。

Currencystyle
已淘汰.

<strong>[icu]</strong> Constant 用以指定一般的貨幣格式。

FractionField
已淘汰.

場常數用於建構 FieldPosition 物件。

IntegerField
已淘汰.

場常數用於建構 FieldPosition 物件。

Integerstyle
已淘汰.

<強[>icu]</strong> 常數用來指定整數格式。

Isocurrencystyle
已淘汰.

<strong>[icu]</strong> Constant 用來指定使用貨幣 ISO 代碼來表示貨幣的貨幣格式,例如:「USD3。

Numberstyle
已淘汰.

<強[>icu]</強> 常數用來指定格式的正規數。

Percentstyle
已淘汰.

<strong>[icu]</strong> 常數用來指定一種格式以顯示百分比。

Pluralcurrencystyle
已淘汰.

<strong>[icu]</strong> Constant 用來指定貨幣格式,使用貨幣長名稱並複數格式表示貨幣,例如「3.

Scientificstyle
已淘汰.

<strong>[icu]</strong> 常數用來指定一種格式以顯示科學數字。

Standardcurrencystyle
已淘汰.

<strong>[icu]</strong> 常數用來指定使用貨幣符號來表示貨幣的格式,例如「$3.

屬性

名稱 Description
Class

回傳此 Object的執行時類別。

(繼承來源 Object)
Currency

回傳 Currency 用於顯示貨幣金額的物件。 -或- 設定 Currency 用於顯示貨幣金額的物件。

CurrencyInstance

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GroupingUsed

若使用此格式的分組,則會回傳真值。 -或- 設定在此格式中是否使用分組。

Handle

底層 Android 實例的帳號。

(繼承來源 Object)
Instance

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

IntegerInstance

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

JniIdentityHashCode

取得由互通執行時指派給此 Java 對等端的身份雜湊碼。

(繼承來源 Object)
JniManagedPeerState

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
JniPeerMembers

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

MaximumFractionDigits

回傳數字分數部分允許的最大位數。 -或- 設定數字分數部分中允許的最大位數。

MaximumIntegerDigits

回傳數字整數部分允許的最大位數。 -或- 設定數字整數部分允許的最大位數。

MinimumFractionDigits

回傳數字分數部分中允許的最小位數。 -或- 設定數字分數部分中允許的最小位數。

MinimumIntegerDigits

回傳數字整數部分允許的最小位數。 -或- 設定數字整數部分允許的最小數字數。

NumberInstance

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

ParseIntegerOnly

如果此格式僅解析數字為整數,則回傳為真。 -或- 設定解析時是否忽略數字的分數部分(預設為 false)。

ParseStrict

<strong>[icu]</strong> 回傳是否實施嚴格解析。 -或- <強[>icu]</strong> 集合,是否實施嚴格語法分析。

PeerReference

取得這個 Java 節點的 JNI 物件參考。

(繼承來源 Object)
PercentInstance

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

RoundingMode

回傳此數字格式中使用的四捨五入模式。 -或- 設定此數字格式中使用的四捨五入模式。

ScientificInstance

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

ThresholdClass

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

ThresholdType

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

方法

名稱 Description
Clone()

建立並回傳此物件的副本。

(繼承來源 _Format)
Construct(JniObjectReference, JniObjectReferenceOptions)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
Dispose()

釋放該 Java 節點所持有的資源。

(繼承來源 Object)
Dispose(Boolean)

釋放該 Java 節點所持有的資源。

(繼承來源 Object)
DisposeUnlessReferenced()

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
Equals(Object)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
Equals(Object)

表示是否有其他物體「等同」於此物。

(繼承來源 Object)
Format(BigDecimal, StringBuffer, FieldPosition)

<強[>重症監護病房]</強格式> ,加護病房大十進位。

Format(BigDecimal, StringBuffer, FieldPosition)

<強力>[重症監護病房]</強力> 格式:大十進位。

Format(BigDecimal)

方便格式化大十進制的方法。

Format(BigDecimal)

<強>[重症監護室]</強力> 便利方法來格式化加護病房大十進位。

Format(BigInteger, StringBuffer, FieldPosition)

<強力>[iccu]</強格式> 為大整數。

Format(BigInteger)

<強[>icu]</strong> 便利方法來格式化一個大整數。

Format(CurrencyAmount, StringBuffer, FieldPosition)

<強力>[iccu]</強格式> 貨幣金額。

Format(CurrencyAmount)

<強>[icu]</strong> 便利性方法來格式化貨幣金額。

Format(Double, StringBuffer, FieldPosition)

格式的專業化。

Format(Double)

格式的專業化。

Format(Int64, StringBuffer, FieldPosition)

格式的專業化。

Format(Int64)

格式的專業化。

Format(Object, StringBuffer, FieldPosition)

格式化一個數字,並將所得文字附加到給定的字串緩衝區。

Format(Object)

格式化物件以產生字串。

(繼承來源 _Format)
FormatToCharacterIterator(Object)

格式化物件產生 AttributedCharacterIterator。

(繼承來源 _Format)
GetAvailableLocales()

回傳可用 NumberFormats 的地點列表。

GetContext(DisplayContext+Type)

[加護病房]取得格式化器的 DisplayContext 值,針對指定的 DisplayContext.Type,例如 CAPITALIZATION。

GetCurrencyInstance(Locale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetCurrencyInstance(ULocale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetHashCode()

回傳物件的雜湊碼值。

(繼承來源 Object)
GetInstance(Locale, NumberFormatStyles)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetInstance(Locale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetInstance(NumberFormatStyles)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetInstance(ULocale, NumberFormatStyles)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetInstance(ULocale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetIntegerInstance(Locale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetIntegerInstance(ULocale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetNumberInstance(Locale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetNumberInstance(ULocale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetPattern(ULocale, Int32)

回傳所提供的地點與選擇的圖案。

GetPercentInstance(Locale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetPercentInstance(ULocale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetScientificInstance(Locale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

GetScientificInstance(ULocale)

<強力>注意:</強力> 強烈建議新手使用 NumberFormatter NumberFormat代替NumberFormat。

JavaFinalize()
已淘汰.

當垃圾回收判定該物件不再有相關參考時,由垃圾回收器呼叫。

(繼承來源 Object)
Notify()

喚醒一個正在該物件監視器上等待的執行緒。

(繼承來源 Object)
NotifyAll()

喚醒所有等待該物件監視器的執行緒。

(繼承來源 Object)
Parse(String, ParsePosition)

如果可能的話,回放多頭(例如:

Parse(String)

從給定字串的開頭解析文字以產生一個數字。

ParseCurrency(ICharSequence, ParsePosition)

將給定字串中的文字解析為 CurrencyAmount。

ParseCurrency(String, ParsePosition)

將給定字串中的文字解析為 CurrencyAmount。

ParseObject(String, ParsePosition)

從字串中解析文字以產生一個數字。

ParseObject(String)

解析給定字串開頭的文字以產生物件。

(繼承來源 _Format)
SetContext(DisplayContext)

<strong>[icu]</strong> 在格式化器中設定特定的 DisplayContext 值,例如 CAPITALIZATION_FOR_STANDALONE。

SetHandle(IntPtr, JniHandleOwnership)

設定 Handle 屬性。

(繼承來源 Object)
SetPeerReference(JniObjectReference, JniObjectReferenceOptions)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
ToArray<T>()

從這個 Java 陣列包裝器建立一個受管理陣列。

(繼承來源 Object)
ToString()

回傳物件的字串表示。

(繼承來源 Object)
UnregisterFromRuntime()

將此 Java 節點從互通執行時中取消註冊。

(繼承來源 Object)
Wait()

導致目前執行緒等待被喚醒,通常是透過 <em>通知</><em 或 em>中斷</em> 來喚醒。

(繼承來源 Object)
Wait(Int64, Int32)

會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。

(繼承來源 Object)
Wait(Int64)

會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。

(繼承來源 Object)

明確介面實作

名稱 Description
IJavaPeerable.Disposed()

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
IJavaPeerable.Finalized()

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 JavaObject)
IJavaPeerable.UnregisterFromRuntime()

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

(繼承來源 _Format)

擴充方法

名稱 Description
GetJniTypeName(IJavaPeerable)

取得實例 self類型的 JNI 名稱。

JavaAs<TResult>(IJavaPeerable)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

JavaCast<TResult>(IJavaObject)

執行 Android 執行時檢查型別轉換。

JavaCast<TResult>(IJavaObject)

<強力>加護病房增強</強力> 加護病房取代 java.text.NumberFormat了。

TryJavaCast<TResult>(IJavaPeerable, TResult)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

適用於