jeudi 17 septembre 2020

Convert Byetes to MegaBytes with exact values [duplicate]

Like for example as from the calculated values shows some how gets truncated after decimal.The answer comes 102323.00 but actual answer is 102323.51

std::string convertBytesToMB( long long int value,  int decDigits)
 {
     double valueMB = value /1048576;
     std::stringstream ss;
     ss.precision(decDigits);
     ss << fixed;
     ss << valueMB;
     return ss.str();
}

  int main()
  {
     double   sizeDownload = 107293976822;
     std::string  sizeinMB = convertBytesToMB(sizeDownload, 2);
     std::cout <<  sizeinMB << std::endl;
  }

Aucun commentaire:

Enregistrer un commentaire