[Flutter] num of Dart data type
1. Write in front
Introduced in the previous articleDart
ofwas
,final
andconst
grammar and usage, then continue to learn nowDart
The basic grammar of it!
[Flutter] Apple Mac computer configuration flutter development environment
[Flutter] Android Studio installs a third-party emulator - Netease MuMu
[Flutter] Project running error Failed to find Build Tools revision 29.0.2
【Flutter】flutter doctor 报错Android license status unknown. Run `flutter doctor --android-licenses‘
[Flutter] How to create a new project and run your first flutter project
[Flutter] Basic use of var, final and const in Dart
2. Numeric type num
existdart
language, numeric typesnumber
divided into twoint
anddouble
.
2.1 int type
void main ( ) {
numTest();
}
void numTest ( ) {
//number numeric int and double
num a = 1 ;
print ( a ) ;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
The results are as follows:
2.2 double type
void numTest ( ) {
//number numeric int and double
num a = 1 ;
print ( a ) ;
a = 3.4 ;
print ( a ) ;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
The results are as follows:
Need noton one
declaration, can be used directlyint
anddouble
Also can.
void numTest ( ) {
//number numeric int and double
num a = 1 ;
print ( a ) ;
a = 3.4 ;
print ( a ) ;
int b = 4;
print(b);
double c = 3.3;
print(c);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
operation result:
double
assignable typeint
Integer,int
type is not assignabledouble
.
2.3 Common methods
There are also some commonly used methods, such as judgmentodd number
still iseven
, subtraction, addition, multiplication and division (+ - * / ), modulo (%
) and a special rounding (~/
).
void numTest ( ) {
//number numeric int and double
num a = 1 ;
print ( a ) ;
a = 3.4 ;
print ( a ) ;
int b = 4;
print(b);
double c = 3 ; //equivalent to 3.0
print ( c ) ;
print ( b . isEven ) ; // is even
print ( b . isOdd ) ; // is odd
print ( b ~ / c ) ; // round up
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
The results are as follows:
2.4 Type conversion
isEven
is even,isOdd
Odd or not, this is onlyint
type can only be called, thendouble
If you want to call the type, you need to convert the type.
int
types can also be converted todouble
Yes, types can be converted to each other.
3. Write at the back
Follow me, more content will continue to be output
🌹 If you like it, give it a like👍🌹
🌹 If you think you have something to gain, you can come to a wave of favorites + follow, so as not to find me next time😁🌹
🌹Welcome everyone to leave a message to exchange, criticize and correct,
Forward
Please indicate the source, thank you for your support! 🌹