EMPIREDB-354
Auto-round BigDecimal if scale is exceeded
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
index c206bb1..207cdb8 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
@@ -99,7 +99,7 @@
         compList.add(input);

         // add unit

         String unit = getUnitString(ii);

-        if (StringUtils.isNotEmpty(unit) && !hasFormatOption(ii, "nounit"))

+        if (StringUtils.isNotEmpty(unit))

         {   // add the unit

             compList.add(createUnitLabel("eUnit", ii, unit));

         }

@@ -366,7 +366,7 @@
         writer.append(text);

         // unit?

         String unit = getUnitString(vi);

-        if (StringUtils.isNotEmpty(unit) && !hasFormatOption(vi, "nounit"))

+        if (StringUtils.isNotEmpty(unit))

         { // append unit

             writer.append(" ");

             writer.append(unit);

@@ -584,7 +584,7 @@
         String format = getFormatString(vi, TextInputControl.FORMAT_UNIT, TextInputControl.FORMAT_UNIT_ATTRIBUTE);

         if (format != null)

         {

-            return vi.getTextResolver().resolveText(format);

+            return (format.length()>0 ? vi.getTextResolver().resolveText(format) : null);

         }

         // Is it a currency column

         Column column = vi.getColumn();

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java b/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
index 4a3447a..47e11bf 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
@@ -19,6 +19,7 @@
 package org.apache.empire.db;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.sql.Connection;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -449,7 +450,7 @@
                     }
                 }
                 // validate Number
-                validateNumber(type, (Number)value);
+                value = validateNumber(type, (Number)value);
                 break;
 
             case FLOAT:
@@ -465,7 +466,7 @@
                     }
                 }
                 // validate Number
-                validateNumber(type, (Number)value);
+                value = validateNumber(type, (Number)value);
                 break;
 
             case INTEGER:
@@ -487,7 +488,7 @@
                     }
                 }
                 // validate Number
-                validateNumber(type, (Number)value);
+                value = validateNumber(type, (Number)value);
                 break;
 
             case TEXT:
@@ -514,7 +515,7 @@
         return value;
     }
     
-    protected void validateNumber(DataType type, Number n)
+    protected Number validateNumber(DataType type, Number n)
     {
         // Check Range
         Object min = getAttribute(Column.COLATTR_MINVALUE);
@@ -554,9 +555,19 @@
             double size = getSize();
             int reqPrec = (int)size;
             int reqScale = getDecimalScale();
-            if ((prec-scale)>(reqPrec-reqScale) || scale>reqScale)
+            if (scale>reqScale)
+            {   // Round if scale is exceeded
+                dv = dv.setScale(reqScale, RoundingMode.HALF_UP);
+                prec  = dv.precision();
+                scale = dv.scale();
+                n = dv;
+            }
+            if ((prec-scale)>(reqPrec-reqScale))
+            {   
                 throw new FieldValueOutOfRangeException(this);
+            }
         }
+        return n;
     }
 
     /**