parseDoubleOrInt static method

double parseDoubleOrInt(
  1. dynamic data
)

fix when api return value someTime in "Int" and sometimes in "Double" like: { "data": 15 } or some times return { "data": 13.5 } remove command "," if found in at big numbers come from backend

Implementation

static double parseDoubleOrInt(dynamic data) {
  if( data  ==  null  ) return 0.0;
  if( data.toString() ==  "null" ) return 0.0;

  String check = data.toString();
  double result = 0.0;

  //fix missed "." dot
  bool isNeedToAddDotCharecter = ToolsString.isContainSingleCharacter(
      mainString: check, charSingle: ".") == false;
  if (isNeedToAddDotCharecter) {
    check = check + ".0";
  }
  String addedDots = check.toString();

  //fix remove all comma ","
  String removedComma = addedDots.replaceAll(RegExp(r','), '');

  result = double.parse(removedComma);
  return result;
}