Actually what I was trying to acheive is round the nearest .5 double value like
var value1 = 23.2 // while rounding --> 23.0
var value2 = 23.6 // while rounding --> 23.5
var value3 = 23.8 // while rounding --> 24.0
CodePudding user response:
There isn't a function for it but you can simply use this function to get your rounded value:
double roundedValue(double value){
return ((value * 2).round() / 2 ) ;
}
Example:
var value1 = 23.2 ; // while rounding --> 23.0
var value2 = 23.6 ;// while rounding --> 23.5
var value3 = 23.8 ; // while rounding --> 24.0
print(roundedValue(value1));
print(roundedValue(value2));
print(roundedValue(value3));