practice_geomethicMeandian/cpp_impl/src/helpers.cpp

17 lines
408 B
C++
Raw Normal View History

2021-05-01 13:31:59 +00:00
#include "helpers.hpp"
#include <string>
bool floating_point_similar(double a, double b, unsigned char decimal) {
std::string astr = std::to_string(a);
std::string bstr = std::to_string(b);
auto a_index = astr.find_last_of('.');
astr = astr.substr(0, a_index + decimal);
auto b_index = bstr.find_last_of('.');
bstr = bstr.substr(0, b_index + decimal);
return astr == bstr;
}