Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here I did not typecast like we do in java, but I am getting correct output
Why is that so?

Dart
void main() {
	print(10/3);
}


output:
3.3333333333333335

What I have tried:

I tried searching in google ..................................
Posted
Updated 10-Oct-21 22:40pm
Comments
Richard MacCutchan 11-Oct-21 4:19am    
Check the Dart documentation to see how it deals with such expressions.

1 solution

The Dart division operator[^] works on double values. It has a different operator for integer division[^] if you want the same behaviour as Java.

Only the language designers could tell you why it does that. At a guess, they saw how many people were tripped up by the integer division behaviour in other languages, and wanted to avoid that in their language.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900