Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article also participated in the “Digitalstar Project” to win a creative gift package and creative incentive money.

📝 [Flutter] learning to form a record, [programmer essential knowledge]

📔 The introduction and use of num, the basic data type of Flutter Dart.

1. Write at the front

The syntax and use of VAR, final, and const for Dart was introduced in the previous article, so let’s move on to the basic syntax for Dart.

The Apple Mac is configured with the Flutter development environment

Android Studio installs a third-party simulator for Flutter — netease MuMu

Failed to find Build Tools Revision 29.0.2

Android license status unknown. Run ‘Flutter doctor — Android – Licenses’

How to create a Flutter project and run your first Flutter project

Dart uses var, final, and const

2. The value type is num

In dart, the numeric type number is divided into two types, int and double. Let’s look at the use of int first.

2.1 type int

void main(a){

  numTest();
}

void numTest(a){
  //number specifies the numeric type int and double
  num a = 1;
  print(a);
}
Copy the code

The running results are as follows:

2.2 type double

void numTest(a){
  //number specifies the numeric type int and double
  num a = 1;
  print(a);
  a = 3.4;
  print(a);
}
Copy the code

The running results are as follows:

Don’t have tonumDeclaration, can be used directlyintdoubleCan also.

void numTest(a){
  //number specifies the numeric type int and double
  num a = 1;
  print(a);
  a = 3.4;
  print(a);

  int b = 4;
  print(b);

  double c = 3.3;
  print(c);
}
Copy the code

Running results:

Double can be assigned to an int, but int cannot be assigned to a double.

2.3 Common Methods

There are some common methods, such as determining odd or even numbers, subtracting, multiplying, and dividing (+ – * /), modulo (%), and a special round (~/).

void numTest(a){
  //number specifies the numeric type 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 it even
  print(b.isOdd);// Is it odd

  print(b~/c);/ / integer

}
Copy the code

The running results are as follows:

2.4 Type Conversion

Whether isEven isEven, whether isOdd isOdd, that’s only an int, so if you want to call a double, you need to cast it.

Ints can also be converted to double, and the types can be converted to each other.

3. Write in the back

Follow me, more content continues to output

  • CSDN
  • The Denver nuggets
  • Jane’s book

🌹 if you like, give it a thumbs up 👍🌹

🌹 feel harvest, can come to a wave of collection + attention, so as not to find you next time I 😁🌹

🌹 welcome everyone to leave a message exchange, criticism and correction, forwarding please indicate the source, thank you for your support! 🌹