From 724792d0cfe7412bf1cc825715f3f8a4d2481781 Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Tue, 7 Jun 2016 16:05:12 -0700 Subject: [PATCH] Fixed rounding logic in TypedValue to handle negative values correctly Simple rounding by +.5 doesn't work for negative values. one-line fix. Issue #26884580 Resources#getDimensionPixelSize rounds incorrectly for negative values Change-Id: Ib2314f7e50320dde87d4c5035a59b49e8f015eaf --- core/java/android/util/TypedValue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/util/TypedValue.java b/core/java/android/util/TypedValue.java index bd00aba325ea9..4ae5a2921547d 100644 --- a/core/java/android/util/TypedValue.java +++ b/core/java/android/util/TypedValue.java @@ -300,7 +300,7 @@ public class TypedValue { (data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK, value, metrics); - final int res = (int)(f+0.5f); + final int res = (int) ((f >= 0) ? (f + 0.5f) : (f - 0.5f)); if (res != 0) return res; if (value == 0) return 0; if (value > 0) return 1;