Repository: frappe/frappe

Issue:
Float Precision
<!--
Welcome to the Frappe Framework issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to Frappe
    - For questions and general support, use https://stackoverflow.com/questions/tagged/frappe
    - For documentation issues, refer to https://frappeframework.com/docs/user/en or the developer cheetsheet https://github.com/frappe/frappe/wiki/Developer-Cheatsheet
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
4. If you think you know what the reason for the bug is, share it with us. Maybe put in a PR 😉
-->

## Description of the issue

**Float Precision** can be set upto nine decimal places under **System Settings** (https://docs.erpnext.com/docs/user/manual/en/customize-erpnext/articles/set-precision). But it seems only a maximum of 6 decimal places will be saved.

On the other hand, if the precision of a specific **Float** field is set directly to more than 6 decimal places it seems to work.

## Context information (for bug reports)

**Output of `bench version`**
```
frappe 13.0.0-beta.7
```

## Steps to reproduce the issue

1. Set Float Precision to 7, 8 or 9 decimal places. (Home > Settings > System Settings)
2. Find a **Float** Field, enter a value with 7, 8 or 9 decimal places and save the document
3. Hard Reload (https://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache)

### Observed result

Decimal places after the 6th are replaced by 0s.

### Expected result

All decimal places are correctly stored and displayed.

## Additional information

Maybe it has something todo with this ...

https://github.com/frappe/frappe/blob/0712d01d43c208471c9b3216216f997dc28b5af4/frappe/database/mariadb/database.py#L33

Presumably **Currency** and **Percent** fields are affected as well.


Discussion:

Resolving patch:
diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py
--- a/frappe/database/mariadb/database.py
+++ b/frappe/database/mariadb/database.py
@@ -22,11 +22,11 @@ class MariaDBDatabase(Database):
 	def setup_type_map(self):
 		self.db_type = 'mariadb'
 		self.type_map = {
-			'Currency':		('decimal', '18,6'),
+			'Currency':		('decimal', '21,9'),
 			'Int':			('int', '11'),
 			'Long Int':		('bigint', '20'),
-			'Float':		('decimal', '18,6'),
-			'Percent':		('decimal', '18,6'),
+			'Float':		('decimal', '21,9'),
+			'Percent':		('decimal', '21,9'),
 			'Check':		('int', '1'),
 			'Small Text':	('text', ''),
 			'Long Text':	('longtext', ''),
@@ -51,7 +51,7 @@ def setup_type_map(self):
 			'Color':		('varchar', self.VARCHAR_LEN),
 			'Barcode':		('longtext', ''),
 			'Geolocation':	('longtext', ''),
-			'Duration':		('decimal', '18,6'),
+			'Duration':		('decimal', '21,9'),
 			'Icon':			('varchar', self.VARCHAR_LEN)
 		}
 
diff --git a/frappe/database/postgres/database.py b/frappe/database/postgres/database.py
--- a/frappe/database/postgres/database.py
+++ b/frappe/database/postgres/database.py
@@ -32,11 +32,11 @@ class PostgresDatabase(Database):
 	def setup_type_map(self):
 		self.db_type = 'postgres'
 		self.type_map = {
-			'Currency':		('decimal', '18,6'),
+			'Currency':		('decimal', '21,9'),
 			'Int':			('bigint', None),
 			'Long Int':		('bigint', None),
-			'Float':		('decimal', '18,6'),
-			'Percent':		('decimal', '18,6'),
+			'Float':		('decimal', '21,9'),
+			'Percent':		('decimal', '21,9'),
 			'Check':		('smallint', None),
 			'Small Text':	('text', ''),
 			'Long Text':	('text', ''),
@@ -61,7 +61,7 @@ def setup_type_map(self):
 			'Color':		('varchar', self.VARCHAR_LEN),
 			'Barcode':		('text', ''),
 			'Geolocation':	('text', ''),
-			'Duration':		('decimal', '18,6'),
+			'Duration':		('decimal', '21,9'),
 			'Icon':			('varchar', self.VARCHAR_LEN)
 		}
 
diff --git a/frappe/database/schema.py b/frappe/database/schema.py
--- a/frappe/database/schema.py
+++ b/frappe/database/schema.py
@@ -303,6 +303,8 @@ def get_definition(fieldtype, precision=None, length=None):
 	size = d[1] if d[1] else None
 
 	if size:
+		# This check needs to exist for backward compatibility.
+		# Till V13, default size used for float, currency and percent are (18, 6).
 		if fieldtype in ["Float", "Currency", "Percent"] and cint(precision) > 6:
 			size = '21,9'
 


Test patch: