Skip to content

Instantly share code, notes, and snippets.

@pezy
Created April 26, 2016 02:41
Show Gist options
  • Save pezy/33b6fb351cae8b8b820162a4e54ef0bf to your computer and use it in GitHub Desktop.
Save pezy/33b6fb351cae8b8b820162a4e54ef0bf to your computer and use it in GitHub Desktop.
#define CATCH_CONFIG_MAIN
#include <string>
#include <iostream>
#include "catch.hpp"
std::string trimToString(double dValue)
{
std::string strRst = std::to_string(dValue);
while (strRst.back() == '0') strRst.pop_back();
if (strRst.back() == '.') strRst.pop_back();
return strRst;
}
TEST_CASE("double trim to string", "[trimToString]") {
REQUIRE(trimToString(23.5600) == "23.56");
REQUIRE(trimToString(2356000) == "2356000");
REQUIRE(trimToString(37.000) == "37");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment