學習筆記——Java數文書處理類

來源:互聯網
上載者:User

標籤:

1.數字格式化

  使用Java.text.DecimalFormat格式化數字,一般使用其中的DecimalFormat類。如:

import java.text.DecimalFormat;public class DecimalFormatdemo{    static public void simpleformat(String pattern,double value){        DecimalFormat myformat=new DecimalFormat(pattern);        String out=myformat.format(value);        System.out.println(value+" "+pattern+" "+out);    }    public static void main(String[] args){        simpleformat("###,###.###",123456.789);    }}    

  學會查看DecimalFormat類的其他方法進行格式化處理。

2.數字運算

2.1 Math類

  如:Math.數學方法(三角函數、指數函數、取整、最大最小值、絕對值)

2.2 隨機數:Math.random()方法

2.3 Random類

  需要import java.util.Random;該類用來產生各種基本類型的隨機數,如:nextInt()、nextDouble()等方法。

2.4 大數字運算BigInteger、BigDecimal類

  由於基本類型Int的最大值為2的31次方減1,如果要計算更大的數字,引入了BigInteger類。使用時,需要import java.math.Biginteger(BigDecimal)。

    api文檔:http://docs.oracle.com/javase/7/docs/api/

  

 

學習筆記——Java數文書處理類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.