| 224 | } |
| 225 | |
| 226 | String withPrecision(int precision) const { |
| 227 | size_t pos = find('.'); |
| 228 | |
| 229 | if (pos == std::u32string::npos) |
| 230 | return string_; |
| 231 | |
| 232 | pos += precision + 1; |
| 233 | if (pos < string_.length()) { |
| 234 | std::u32string result = string_.substr(0, string_[pos - 1] == '.' ? pos - 1 : pos); |
| 235 | bool carry = string_[pos] >= '5'; |
| 236 | while (pos > 0 && carry) { |
| 237 | --pos; |
| 238 | if (string_[pos] == '9') |
| 239 | result[pos] = '0'; |
| 240 | else if (string_[pos] != '.') { |
| 241 | ++result[pos]; |
| 242 | carry = false; |
| 243 | } |
| 244 | } |
| 245 | if (carry) |
| 246 | return U"1" + result; |
| 247 | |
| 248 | return result; |
| 249 | } |
| 250 | |
| 251 | return string_ + std::u32string(pos - string_.length(), '0'); |
| 252 | } |
| 253 | |
| 254 | std::wstring toWide() const { return convertToWide(string_); } |
| 255 | std::string toUtf8() const { return convertToUtf8(string_); } |
no test coverage detected