diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h
index 66db51014e2afda05787e55144669bf65367330d..7bb846026aea73dde23f71b6382ec5ec7a0dd203 100644
--- a/gdb/gmp-utils.h
+++ b/gdb/gmp-utils.h
@@ -388,10 +388,8 @@ struct gdb_mpq
 
 struct gdb_mpf
 {
-  mpf_t val;
-
   /* Constructors.  */
-  gdb_mpf () { mpf_init (val); }
+  gdb_mpf () { mpf_init (m_val); }
 
   DISABLE_COPY_AND_ASSIGN (gdb_mpf);
 
@@ -409,11 +407,20 @@ struct gdb_mpf
     gdb_mpq tmp_q;
 
     tmp_q.read_fixed_point (buf, byte_order, unsigned_p, scaling_factor);
-    mpf_set_q (val, tmp_q.m_val);
+    mpf_set_q (m_val, tmp_q.m_val);
   }
 
+  /* Convert this value to a string.  FMT is the format to use, and
+     should have a single '%' substitution.  */
+  std::string str (const char *fmt) const
+  { return gmp_string_printf (fmt, m_val); }
+
   /* The destructor.  */
-  ~gdb_mpf () { mpf_clear (val); }
+  ~gdb_mpf () { mpf_clear (m_val); }
+
+private:
+
+  mpf_t m_val;
 };
 
 /* See declaration above.  */
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 357db3815b076776f74611fb2b5dd9ebd3f886a1..b05d90dd26b760c2fd339cfb7619f733457ac77d 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -856,7 +856,7 @@ generic_val_print_fixed_point (struct value *val, struct ui_file *stream,
 			  type->fixed_point_scaling_factor ());
 
       const char *fmt = type->length () < 4 ? "%.11Fg" : "%.17Fg";
-      std::string str = gmp_string_printf (fmt, f.val);
+      std::string str = f.str (fmt);
       gdb_printf (stream, "%s", str.c_str ());
     }
 }