diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index bcc041ae9c6..3e083219a07 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2642,12 +2642,12 @@ String *Item_func_soundex::val_str(String *str)
   This should be 'internationalized' sometimes.
 */
 
-const int FORMAT_MAX_DECIMALS= 30;
+const int FORMAT_MAX_DECIMALS= 38;
 
 
 bool Item_func_format::fix_length_and_dec()
 {
-  uint32 char_length= args[0]->type_handler()->Item_decimal_notation_int_digits(args[0]);
+  uint32 char_length= args[0]->type_handler()->Item_decimal_notation_int_digits(args[0]) + 1;
   uint dec= FORMAT_MAX_DECIMALS;
   if (args[1]->const_item() && !args[1]->is_expensive() && !args[1]->null_value)
   {
