{

# How to Check given number is an integer or whole number or decimal number in dart | Flutter By Example

In Dart, We have two numerical types - int, double

`int` represents whole numbers, that contain no fractional or decimal digits `double` stores the floating numbers that contain decimal values.

## how to check given number is int or double?

There are multiple ways we can check

• using is Operator

dart is the operator used to check the variable of a given type or not

Syntax:

``````variable is datatype
``````

Returns true if the variable of a given datatype else returns false. This check is added as an extension to num type.

Here is an example program to check given number is int or double.

``````void main() {
num intValue = 12;
num doubleValue = 11.12;
print(intValue.isIntValue()); // true
print(doubleValue.isIntValue()); // false
}

extension WholeNumber on num {
bool isIntValue() => this is int;
}

``````
• using Modulus Operator

The modulus operator gives a remainder after two operand divisions.

if the given number is a whole number, Then the value is divided by 1 and gives the remainder as zero if the given number is a double or fractional decimal value, Then the remainder is not zero after division by 1

Here is an example program to check given number contains a fractional decimal or not.

``````void main() {
num intValue = 12;
num doubleValue = 11.12;
print(intValue.isIntValue()); // true
print(doubleValue.isIntValue()); // false
}

extension WholeNumber on num {
bool isIntValue() => (this % 1) == 0;
}

``````
• use toInt method

The given number is truncated using the `toInt` method. If the given number is 11.12, toInt returns int number i.e 11. Checks the original value and result, if both are equal, It is an integer number.

Here is an example program

``````void main() {
num intValue = 12;
num doubleValue = 11.12;
print(intValue.isIntValue()); // true
print(doubleValue.isIntValue()); // false
}

extension WholeNumber on num {
bool isIntValue() => this ==this.toInt();
}
``````

## Conclusion

There are multiple ways to check given a number is a whole number or fractional decimal number in dart examples below approaches.

• use toInt method
• dart is the operator
• using Modulus Operator
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.

Related posts
{"ft_lang_label":"__label__en","ft_lang_prob":0.63001287,"math_prob":0.99572086,"size":2055,"snap":"2022-40-2023-06","text_gpt3_token_len":480,"char_repetition_ratio":0.1569966,"word_repetition_ratio":0.26530612,"special_character_ratio":0.24768856,"punctuation_ratio":0.125,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9992704,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-29T01:56:25Z\",\"WARC-Record-ID\":\"<urn:uuid:aa7d8224-5c9c-4891-85ff-e29bc2417060>\",\"Content-Length\":\"54960\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:98826448-e4fa-4ec3-ac0c-bed5dbca5d24>\",\"WARC-Concurrent-To\":\"<urn:uuid:e5aa0ccc-68bb-44cc-a49f-89c4dd3198a2>\",\"WARC-IP-Address\":\"52.86.133.10\",\"WARC-Target-URI\":\"https://www.cloudhadoop.com/dart-integer-check-integer-decimal/\",\"WARC-Payload-Digest\":\"sha1:G7HK2SQB3XN5A67ZFBIIL2HYTDSQTMTQ\",\"WARC-Block-Digest\":\"sha1:AG4BQQHJRLYVA2LJXDSEPKRQBVOCUJLO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030335303.67_warc_CC-MAIN-20220929003121-20220929033121-00006.warc.gz\"}"}