Created
April 26, 2016 02:41
-
-
Save pezy/33b6fb351cae8b8b820162a4e54ef0bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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