بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
نمایش در هنگام وارد کردن اعداد در edittext به اینصورت : 1،000،000،000،000،000
چگونه در edittext اعداد را اینگونه وارد کنیم تا بهتر نمایش داده شود ؟ (Mask) ?
1،000،000،000،000،000
5,000,666,778,322
در هنگام وارد کردن اعداد در edittext نمایش این اعداد در همان لحظه سه رقم سه رقم از هم جدا شود؟
برای این سوال 1 پاسخ وجود دارد.

پاسخ به سوال
Dadparvar
10 سال پیش
+7
0
اگر منظورتون جداکردن هر سه عدد با یک ، هستش به کدهای زیر دقت کنید. انواع Number Format ها رو در جاوا نشون میده.توضیحات هم بصورت کامنت در بالای هرکد درج شده
package com.javacodegeeks.core.numformat; import java.math.BigDecimal; import java.text.DecimalFormat; public class NumberFormaClass { public static void main(String[] args) { double decimal = 7.27467; System.out.println("The test number: "+decimal); int decimalPlaces = 3; // the scale for the decimal // use of BigDecimal class BigDecimal bd = new BigDecimal(decimal); // set the scale and round up if >= 0.5 bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); double bigDecimal = bd.doubleValue(); System.out.println("BigDecimal rounded in 3rd decimal: "+bigDecimal); // use of DecimalFormat DecimalFormat decFormat = new DecimalFormat("#.00"); double formatDecimal = new Double(decFormat.format(decimal)).doubleValue(); System.out.println("DecimalFormat rounded in 2nd decimal: "+formatDecimal); System.out.println("--------------------------------------"); DecimalFormat numFormat; String number; // 2 digits before decimal point and then 2 digits (rounded) numFormat = new DecimalFormat("000.##"); number = numFormat.format(-15.567); System.out.println("1. DecimalFormat with .: " + number); // string '$' in front of the number numFormat = new DecimalFormat("'$'00.####"); number = numFormat.format(15.567); System.out.println("2. DecimalFormat with '$': " + number); // use of , to group numbers numFormat = new DecimalFormat("#,###,###"); number = numFormat.format(1556789); System.out.println("3. DecimalFormat with ,: " + number); // use of % for percentage numFormat = new DecimalFormat("%"); number = numFormat.format(0.15); System.out.println("4. DecimalFormat with percentage: " + number); // 2 digits before decimal point and 2 digits after numFormat = new DecimalFormat("00.00"); number = numFormat.format(-15.567); System.out.println("5. DecimalFormat with 4 digits: " + number); // left part of decimal number numFormat = new DecimalFormat("##"); number = numFormat.format(156.567); System.out.println("6. DecimalFormat with no decimal part: " + number); // 5 or less digits in the decimal part numFormat = new DecimalFormat(".#####"); number = numFormat.format(1890.567); System.out.println("7. DecimalFormat with 5 or less digits (in decimal part): " + number); // string 'JCG' in front of the number numFormat = new DecimalFormat("'JCG'000.#"); number = numFormat.format(15.567); System.out.println("8. DecimalFormat with 'JCG': " + number); } }
نتیجه کد بالا ، خروجی زیر خواهد شد:
The test number: 7.27467
BigDecimal rounded in 3rd decimal: 7.275
DecimalFormat rounded in 2nd decimal: 7.27
--------------------------------------
1. DecimalFormat with .: -015.57
2. DecimalFormat with '$': $15.567
3. DecimalFormat with ,: 1,556,789
4. DecimalFormat with percentage: %15
5. DecimalFormat with 4 digits: -15.57
6. DecimalFormat with no decimal part: 157
7. DecimalFormat with 5 or less digits (in decimal part): 1890.567
8. DecimalFormat with 'JCG': JCG015.6
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .