diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-04 08:21:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-04 08:21:51 +0400 |
commit | 24da4a6032543e3bdae5960e8b956caa25b38aae (patch) | |
tree | 413fa05306ca964d15c54e39b55f619a858e7696 /source/blender/blenlib | |
parent | c2157518de1ff81e5f8f2842bb13ef49de8f635c (diff) |
fix [#34490] Copy and paste floating point number fields losses precision
- copy now gets up to 6 decimal places
- copy and UI float button editing now strip zeros: 1.000 -> 1.0
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 28 |
2 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 70c89773f02..603831246ac 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -226,6 +226,11 @@ void BLI_ascii_strtoupper(char *str, const size_t len) __attribute__((nonnull)) #endif ; +int BLI_str_rstrip_float_zero(char *str, const char pad) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; #ifdef __cplusplus } 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; +} |