Java Android 开发数字不足位数前面补0,oracle不足位数补0
分享于 点击 20186 次 点评:79
Java Android 开发数字不足位数前面补0,oracle不足位数补0
import java.text.DecimalFormat; public void changeColor(View view) { DecimalFormat decimalFormat = new DecimalFormat("000"); //获取随机数对象,产生三个随机数值(RGB值) Random x = new Random(); int red = x.nextInt(256); String sred = decimalFormat.format(red); txvR.setText("红:"+sred); txvR.setTextColor(Color.rgb(red,0,0)); int green = x.nextInt(256); String sgreen = decimalFormat.format(green); txvG.setText("绿:"+sgreen); txvG.setTextColor(Color.rgb(0,green,0)); int blue = x.nextInt(256); String sblue = decimalFormat.format(blue); txvB.setText("蓝:"+sblue); txvB.setTextColor(Color.rgb(0,0,blue)); //设置界面最上方的按钮 button 的文字颜色 button.setTextColor(Color.rgb(red,green,blue)); //设置界面最下方的空白 LinearLayout 的背景颜色 colorBlock.setBackgroundColor(Color.rgb(red,green,blue)); }
import java.text.DecimalFormat; //如果数字1是字符串,如下处理: String string="1"; DecimalFormat decimalFormat =new DecimalFormat("0000"); String string2=decimalFormat.format(Integer.parseInt(str1)); System.out.println(string2); //如果数字1是整型,如下处理: int string=1; DecimalFormat decimalFormat =new DecimalFormat("0000"); String string2=decimalFormat.format(string); System.out.println(string2);
相关文章
- 暂无相关文章
用户点评