json-tutorial
json-tutorial copied to clipboard
数字解析成字符串出现错误
在visual 2013里面运行tutorial_07的测试用例时以下测试用例会出现错误(在gcc下面测试正常) TEST_ROUNDTRIP("1e+20"); //1e+020 TEST_ROUNDTRIP("1.234e+20"); //1.234e+020 TEST_ROUNDTRIP("1.234e-20"); //1.234e-020
test.c:394: expect: 1e+20 actual: 1e+020 test.c:395: expect: 1.234e+20 actual: 1.234e+020 test.c:396: expect: 1.234e-20 actual: 1.234e-020
指数部分会多一个0,在转化的时候需要去除多余的0。去除后能通过所有测试用例。
https://stackoverflow.com/questions/9226400/portable-printing-of-exponent-of-a-double-to-c-iostreams