[Flutter] num of Dart data type

1. Write in front

Introduced in the previous articleDartofwas,finalandconstgrammar and usage, then continue to learn nowDartThe basic grammar of it!
Flutter

[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

existdartlanguage, numeric typesnumberdivided into twointanddouble.

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:
operation result

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:

operation result
Need noton onedeclaration, can be used directlyintanddoubleAlso 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:
operation result
doubleassignable typeintInteger,inttype is not assignabledouble.
operation result

2.3 Common methods

There are also some commonly used methods, such as judgmentodd numberstill 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:

operation result

2.4 Type conversion

isEvenis even,isOddOdd or not, this is onlyinttype can only be called, thendoubleIf you want to call the type, you need to convert the type.

operation result
inttypes can also be converted todoubleYes, types can be converted to each other.

operation result

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,ForwardPlease indicate the source, thank you for your support! 🌹

Related: [Flutter] num of Dart data type