Usage of the Math class

Source: Internet
Author: User
Tags natural logarithm

Common constants and methods of the Java.math.Math class:

Math.PI recorded by pi
MATH.E Constants for Record E
Math.Abs Absolute Value
Math.sin sine function math.asin inverse chord function
Math.Cos cosine function Math.acos inverse cosine function
Math.tan tangent function Math.atan inverse tangent function   The inverse tangent function of math.atan2 quotient
Convert math.todegrees radians to angles math.toradians angles to radians
Math.ceil get the largest integer not less than a certain number
Math.floor the largest integer less than a certain number

Example: Math.floor (12.7) =12.0

Math.ceil (12.7) =13.0

Ceil () is the ceiling, that is, rounding up. Floor is the ground, rounded down. Round is rounded.

Math.ieeeremainder to seek the remainder
Math.max two number of the largest
Math.min to find the smallest of two numbers
Math.sqrt to seek a prescription
Math.pow the arbitrary order of a number, throws a ArithmeticException handle overflow exception

MATH.SQRT (x): square root
Math.pow (x, y): x y-square

Math.exp the arbitrary order of E
MATH.LOG10 logarithm with base 10
Math.log Natural logarithm
Math.rint the nearest integer (perhaps larger or smaller than a certain number) from a certain number
Math.Round, return int or long (previous function returns double type)
Math.random returns a random number between 0 and 1.

Java.math.BigInteger (Large integer):
BigInteger bi1=new BigInteger ("1234567890123456890");
BigInteger bi2=biginteger.valueof (123L);
Bi1=bi1.add (BI2);//b1+b2
Bi1=bi1.multiply (BI2);//b1*b2
Bi1=bi1.subtract (BI2);//b1-b2
Bi1=bi1.divide (BI2);//B1/B2

Java.math.BigDecimal (large floating point):
BigDecimal bd = new BigDecimal ("3.1415926");
BD = Bd.setscale (2,bigdecimal.round_down);//Take 3.1415926 decimal points after two digits

Usage of the Math class

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.