Advertisement
Radfler

::round_to

Apr 12th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <cmath>
  2. #include <type_traits>
  3.  
  4. template<typename Float>
  5. std::enable_if_t<std::is_floating_point<Float>::value, Float> round_to(Float value, std::size_t place) {
  6.  
  7.     const Float _10 = std::pow(10, place);
  8.     return std::round(value * _10) / _10;
  9.  
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement