Large data factorial operation-java High precision Operation __c language

Source: Internet
Author: User

In Java, two classes with High-precision computations are available: BigInteger and BigDecimal
BigInteger: Support for arbitrary precision integer Operations
BigDecimal: Supports arbitrary precision of fixed-point number, can be accurate currency calculation
Please refer to JDK documentation for details

Import Java.math.BigDecimal;
/**
* High Precision operation
* @author RSun
* @Date 2012-11-7 11:22:04
*/
public class Testbiginteger {
Private static final long SUM = 10; public static void Main (string[] args) {System.out.println ("Start of large data factorial operation ...") Can be new thread operation "); String s = "1"; for (int i = 1; I <= SUM; i++) {

New BigDecimal ("multiplier"). Multiply (new BigDecimal ("factor")). ToString (); BigDecimal stra = new BigDecimal (s); BigDecimal end = new BigDecimal (s); Convert S to BigDecimal BigDecimal re = end.multiply (stra); End*stra s = re.tostring (); Re-assign value to S} System.out.println ("Run complete.") Results: "+s"; } }
Output result: Large data factorial operation begins ...
Run complete. Results: 3628800


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.