Format a floating point value
| 247 | |
| 248 | // Format a floating point value |
| 249 | inline fl::string format_float(double value, const FormatSpec& spec) { |
| 250 | int precision = spec.precision >= 0 ? spec.precision : 6; |
| 251 | |
| 252 | fl::string result; |
| 253 | |
| 254 | // Handle sign |
| 255 | if (value < 0) { |
| 256 | result.append('-'); |
| 257 | value = -value; |
| 258 | } else if (spec.sign == '+') { |
| 259 | result.append('+'); |
| 260 | } else if (spec.sign == ' ') { |
| 261 | result.append(' '); |
| 262 | } |
| 263 | |
| 264 | // Format the number |
| 265 | char buf[64]; |
| 266 | fl::ftoa(static_cast<float>(value), buf, precision); |
| 267 | result.append(buf); |
| 268 | |
| 269 | return result; |
| 270 | } |
| 271 | |
| 272 | // Format a pointer |
| 273 | inline fl::string format_pointer(const void* ptr, const FormatSpec& spec) { |