- Timestamp:
- 08/01/18 19:08:56 (6 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/tools.cc
r18876 r19119 215 215 } 216 216 217 string Tools::Fractional(const double &val) 218 { 219 ostringstream rc; 220 rc << setprecision(1) << fixed; 221 222 const auto abs = fabs(val); 223 224 if (abs>1) 225 { 226 rc << val << " "; 227 return rc.str(); 228 } 229 230 if (abs>1e-3) 231 { 232 rc << val*1000 << " m"; 233 return rc.str(); 234 } 235 236 if (abs>1e-6) 237 { 238 rc << val*1000000 << " u"; 239 return rc.str(); 240 } 241 242 if (abs>1e-9) 243 { 244 rc << val*1000000000 << " n"; 245 return rc.str(); 246 } 247 248 if (abs>1e-12) 249 { 250 rc << val*1000000000000. << " p"; 251 return rc.str(); 252 } 253 254 rc << abs*1000000000000000. << " f"; 255 return rc.str(); 256 } 257 217 258 // -------------------------------------------------------------------------- 218 259 // -
trunk/FACT++/src/tools.h
r18963 r19119 18 18 std::string Wrap(std::string &str, size_t width=78); 19 19 std::string Scientific(uint64_t val); 20 std::string Fractional(const double &val); 20 21 21 22 std::map<std::string,std::string> Split(std::string &, bool = false);
Note:
See TracChangeset
for help on using the changeset viewer.