diff options
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r-- | source/blender/blenlib/intern/string.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 3500f3f1805..08d4f8e1198 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -454,3 +454,31 @@ void BLI_ascii_strtoupper(char *str, const size_t len) if (str[i] >= 'a' && str[i] <= 'z') str[i] -= 'a' - 'A'; } + +/** + * Strip trailing zeros from a float, eg: + * 0.0000 -> 0.0 + * 2.0010 -> 2.001 + * + * \param str + * \param len + * \return The number of zeto's stripped. + */ +int BLI_str_rstrip_float_zero(char *str, const char pad) +{ + char *p = strchr(str, '.'); + int totstrip = 0; + if (p) { + char *end_p; + p++; /* position at first decimal place */ + end_p = p + (strlen(p) - 1); /* position at last character */ + if (end_p > p) { + while (end_p != p && *end_p == '0') { + *end_p = pad; + end_p--; + } + } + } + + return totstrip; +} |