From 6e2a904ed0955b3b4b079f8de952979cf2b12bdd Mon Sep 17 00:00:00 2001
From: "yogeshwar.g" <yogeshwar.g@vtigersolutions.com>
Date: Fri, 26 Apr 2024 11:54:13 +0530
Subject: [PATCH] Fixes #1760:Fixed Handled Percentage Field becoming rounded
 if no of decimal is Zero

---
 modules/Vtiger/uitypes/Percentage.php | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/modules/Vtiger/uitypes/Percentage.php b/modules/Vtiger/uitypes/Percentage.php
index 4477d8b91..93815bc50 100644
--- a/modules/Vtiger/uitypes/Percentage.php
+++ b/modules/Vtiger/uitypes/Percentage.php
@@ -21,9 +21,29 @@ class Vtiger_Percentage_UIType extends Vtiger_Base_UIType {
 	public function getDisplayValue($value, $record = false, $recordInstance = false) {
 		$fldvalue = str_replace(",", ".", $value);
 		$value = (is_numeric($fldvalue)) ? $fldvalue : null;
-		return CurrencyField::convertToUserFormat($value, null, true);
+		return Vtiger_Percentage_UIType::convertToUserFormat($value, null, true);
 	}
 
+	public static function convertToUserFormat($value, $user = null, $skipConversion = false, $skipFormatting = false) {
+		
+		if (empty($value)) {
+            return $value;
+        }
+		if (empty($user)) {
+            $user = Users_Record_Model::getCurrentUserModel();
+        }
+		$old_no_of_currency_decimals = $user->no_of_currency_decimals;
+        // If decimal separator is "," and no.of decimals is "0" then if we give 8,8 (value:8.8) 
+        // which is becoming round of value i,e "9". 
+        // so by default we are setting no_of_currency_decimals to max value.
+        $user->no_of_currency_decimals = 5;
+
+        $currencyField = new CurrencyField($value);
+        $display_value = $currencyField->getDisplayValue($user, $skipConversion, $skipFormatting);
+        $user->no_of_currency_decimals = $old_no_of_currency_decimals;
+        return $display_value;
+    }
+
 	public function getEditViewDisplayValue($value) {
 		return $this->getDisplayValue($value);
 	}
-- 
GitLab