Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-03-04 08:21:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-03-04 08:21:51 +0400
commit24da4a6032543e3bdae5960e8b956caa25b38aae (patch)
tree413fa05306ca964d15c54e39b55f619a858e7696 /source/blender/blenlib/intern/string.c
parentc2157518de1ff81e5f8f2842bb13ef49de8f635c (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/intern/string.c')
-rw-r--r--source/blender/blenlib/intern/string.c28
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;
+}