Declare A Float Number In Dart
Code snippet for how to Declare A Float Number In Dart with sample and detail explanation
Dart programming language is used extensively in software development. This article will focus on showing you how to declare a float number in Dart language.
Code snippet to Declare A Float Number In Dart
In Dart programming language, declaring a float number is a straightforward task. Here is a sample demonstration:
void main() {
double num1 = 5.23;
print('The value of num1 is $num1');
}
Code Explanation for Declare A Float Number In Dart
In the Dart language, double
is used to declare a floating point number. In this tutorial, we break down each step in the code snippet:
-
void main() {...}
- This is the main function where the execution of the code begins. Dart’s foundation library provides a top-level function,main()
, which is the entry point of the application. Without this function, the application cannot execute. -
double num1 = 5.23;
- In this line,num1
is a variable name anddouble
is a data type which specifies thatnum1
is a floating point number.5.23
is the value assigned to the variablenum1
. In Dart, you don’t require to specify the data type explicitly; Dart will automatically infer thatnum1
is ofdouble
type. -
print('The value of num1 is $num1');
- This command is used to print the value of the variablenum1
. Here$num1
is a template literal used to reference the value of the variablenum1
. When this line of code executes, it outputs: “The value of num1 is 5.23”.
And that completes our tutorial on how to declare a float number in Dart language. Keep practicing and have fun coding!