diff --git a/sql/item_func.cc b/sql/item_func.cc
index 9e30afd0239..96cb9738409 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2332,6 +2332,21 @@ my_decimal *Item_func_ceiling::decimal_op(my_decimal *decimal_value)
 }
 
 
+bool Item_func_ceiling::fix_length_and_dec()
+{
+  int length_increase= (args[0]->decimals <= 0) ? 0 : 1;
+  int precision= args[0]->decimal_precision() + length_increase -
+                                                args[0]->decimals;
+  set_handler(&type_handler_newdecimal);
+  unsigned_flag= args[0]->unsigned_flag;
+  decimals= 0;
+  max_length= my_decimal_precision_to_length_no_truncation(precision,
+                                                           decimals,
+                                                           unsigned_flag);
+  return false;
+}
+
+
 longlong Item_func_floor::int_op()
 {
   switch (args[0]->result_type()) {
@@ -2372,12 +2387,28 @@ my_decimal *Item_func_floor::decimal_op(my_decimal *decimal_value)
 }
 
 
+bool Item_func_floor::fix_length_and_dec()
+{
+  int length_increase= (args[0]->decimals <= 0) ? 0 : 1;
+  int precision= args[0]->decimal_precision() + length_increase -
+                                                args[0]->decimals;
+  set_handler(&type_handler_newdecimal);
+  unsigned_flag= args[0]->unsigned_flag;
+  decimals= 0;
+  max_length= my_decimal_precision_to_length_no_truncation(precision,
+                                                           decimals,
+                                                           unsigned_flag);
+  return false;
+}
+
+
 void Item_func_round::fix_length_and_dec_decimal(uint decimals_to_set)
 {
   int decimals_delta= args[0]->decimals - decimals_to_set;
   int length_increase= (decimals_delta <= 0 || truncate) ? 0 : 1;
   int precision= args[0]->decimal_precision() + length_increase -
                                                 decimals_delta;
+
   DBUG_ASSERT(decimals_to_set <= DECIMAL_MAX_SCALE);
   set_handler(&type_handler_newdecimal);
   unsigned_flag= args[0]->unsigned_flag;
diff --git a/sql/item_func.h b/sql/item_func.h
index 4922d20bd0c..03e65f74ad6 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -1833,6 +1833,7 @@ class Item_func_ceiling :public Item_func_int_val
   my_decimal *decimal_op(my_decimal *);
   Item *get_copy(THD *thd)
   { return get_item_copy<Item_func_ceiling>(thd, this); }
+  bool fix_length_and_dec();
 };
 
 
@@ -1846,6 +1847,7 @@ class Item_func_floor :public Item_func_int_val
   my_decimal *decimal_op(my_decimal *);
   Item *get_copy(THD *thd)
   { return get_item_copy<Item_func_floor>(thd, this); }
+  bool fix_length_and_dec();
 };
 
 /* This handles round and truncate */
