Advertisement
Vultraz

Untitled

Dec 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. =====
  2. NEW
  3. =====
  4. static std::string get_probability_string(const double prob)
  5. {
  6.     std::ostringstream ss;
  7.  
  8.     if(prob > 0.9995) {
  9.         ss << "100%";
  10.     } else if(prob >= 0.1) {
  11.         ss << 100.0 * prob << std::setw(4) << std::setprecision(1) << '%';
  12.     } else {
  13.         ss << 100.0 * prob << std::setw(3) << std::setprecision(1) << '%';
  14.     }
  15.  
  16.     return ss.str();
  17. }
  18.  
  19. =====
  20. OLD
  21. =====
  22. static void format_prob(char str_buf[10], double prob)
  23. {
  24.  
  25.     if(prob > 0.9995) {
  26.         snprintf(str_buf, 10, "100 %%");
  27.     } else if(prob >= 0.1) {
  28.         snprintf(str_buf, 10, "%4.1f %%", 100.0 * prob);
  29.     } else {
  30.         snprintf(str_buf, 10, " %3.1f %%", 100.0 * prob);
  31.     }
  32.  
  33.     str_buf[9] = '\0';  //prevents _snprintf error
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement