# java syntax - decimal

Posted by mac25 on Sun, 06 Mar 2022 04:07:17 +0100

# Digit base

## Integer expansion

How to deal with binary, decimal, octal and hexadecimal expressions of "10"?

Binary plus 0b

decimal system

Octal plus 0

Hex plus 0x

give an example:

```int i = 10;
int i1 = 010; //Octal 0
int i2 = 0x10; // Hex 0x 0 ~ 9 A ~ F
int i3 = 0b10;
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
```

## Floating point extension

Floating point numbers are finite and discrete, so they are approximate, but close to but not equal to.

Therefore, it is better not to compare with floating-point numbers:

Therefore, it is better not to compare with floating-point numbers:

Therefore, it is better not to compare with floating-point numbers:

give an example:

```float f = 0.1f;
double d = 1.0/10;
System.out.println(f==d); //false
System.out.println(f);
System.out.println(d);

float d1 = 232333334444443f;
float d2= d1 + 1;
System.out.println(d2);
System.out.println(d1==d2);
```

From the output result, f=d=0.1 F should be equal to d

d2=d1+1 D2 is not equal to D1;

However, according to the program judgment, f is not equal to d; d2 equals d1, which is why.

For the comparison of accurate data, we need to use the mathematical tool class: BigDecimal

## Character expansion

All characters are essentially numbers. Cast characters into integer numbers.

give an example:

```char c1 = 'a';
char c2 = 'in';
System.out.println(c1);
System.out.println(c2);
System.out.println((int)c1); //Cast line
System.out.println((int)c2); //Cast line
```
```//Code: byte 0 ~ 65536 of Unicode Table 2 to the 16th power of Excel 2;

// Range of Unicode table: U0000 ~ UFFFF
```

There is a Unicode table in the character and number conversion as the "translation table"

The corresponding output can be viewed with the following instructions:

```char c3 = '\u0061';//Escape character
System.out.println(c3); //a
```

# Digit base

## Integer expansion

How to deal with binary, decimal, octal and hexadecimal expressions of "10"?

Binary plus 0b

decimal system

Octal plus 0

Hex plus 0x

give an example:

```int i = 10;
int i1 = 010; //Octal 0
int i2 = 0x10; // Hex 0x 0 ~ 9 A ~ F
int i3 = 0b10;
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
```

## Floating point extension

Floating point numbers are finite and discrete, so they are approximate, but close to but not equal to.

Therefore, it is better not to compare with floating-point numbers:

Therefore, it is better not to compare with floating-point numbers:

Therefore, it is better not to compare with floating-point numbers:

give an example:

```float f = 0.1f;
double d = 1.0/10;
System.out.println(f==d); //false
System.out.println(f);
System.out.println(d);

float d1 = 232333334444443f;
float d2= d1 + 1;
System.out.println(d2);
System.out.println(d1==d2);
```

From the output result, f=d=0.1 F should be equal to d

d2=d1+1 D2 is not equal to D1;

However, according to the program judgment, f is not equal to d; d2 equals d1, which is why.

For the comparison of accurate data, we need to use the mathematical tool class: BigDecimal

## Character expansion

All characters are essentially numbers. Cast characters into integer numbers.

give an example:

```char c1 = 'a';
char c2 = 'in';
System.out.println(c1);
System.out.println(c2);
System.out.println((int)c1); //Cast line
System.out.println((int)c2); //Cast line
```
```//Code: byte 0 ~ 65536 of Unicode Table 2 to the 16th power of Excel 2;

// Range of Unicode table: U0000 ~ UFFFF
```

There is a Unicode table in the character and number conversion as the "translation table"

The corresponding output can be viewed with the following instructions:

```char c3 = '\u0061';//Escape character
System.out.println(c3); //a
```

Common escape characters include:

```//Transfer character
// \t tab
// \n line feed
// \r enter
// \b backspace
System.out.println("Hello\tWorld");
```

## Boolean extension

boolean flag = true;

if (flag==true) {} is the same as if (flag) {}.
Common escape characters include:

```//Transfer character
// \t tab
// \n line feed
// \r enter
// \b backspace
System.out.println("Hello\tWorld");
```

## Boolean extension

boolean flag = true;

if (flag==true) {} is the same as if (flag) {}.