title: How to format floating point numbers into a string using Go
body: <p>Using Go I'm trying to find the "best" way to format a floating point number into a string. I've looked for examples however I cannot find anything that specifically answers the questions I have.  All I want to do is use the "best" method to format a floating point number into a string. The number of decimal places may vary but will be known (eg. 2 or 4 or zero).
  An example of what I want to achieve is below.</p>
  
  <p>Based on the example below should I use <code>fmt.Sprintf()</code> or <code>strconv.FormatFloat()</code> or something else?</p>
  
  <p>And, what is the normal usage of each and differences between each?</p>
  
  <p>I also don't understand the significance of using either 32 or 64 in the following which currently has 32:</p>
  
  <pre><code>strconv.FormatFloat(float64(fResult), 'f', 2, 32)
  </code></pre>
  
  <p>Example:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "strconv"
  )
  
  func main() {
  
      var (
          fAmt1 float32 = 999.99
          fAmt2 float32 = 222.22
      )
  
      var fResult float32 = float32(int32(fAmt1*100) + int32(fAmt2*100)) / 100
  
      var sResult1 string = fmt.Sprintf("%.2f", fResult)
  
      println("Sprintf value = " + sResult1)
  
      var sResult2 string = strconv.FormatFloat(float64(fResult), 'f', 2, 32)
  
      println("FormatFloat value = " + sResult2)
  
  }
  </code></pre>