title: How to use g.formatNumber in grails Service class
body: <p>I want to use g.formatNumber in service, I have tried a below method, Which i got online. This is not working, its giving me the error <code>"Cannot invoke method formatNumber() on null object"</code>, The code is below</p>
  
  <pre><code>    import org.springframework.beans.factory.InitializingBean
  
      class MyService implements InitializingBean {
          boolean transactional = false
          def gspTagLibraryLookup  // being automatically injected by spring
          def g
  
          public void afterPropertiesSet() {
              g = gspTagLibraryLookup.lookupNamespaceDispatcher("g")
              assert g
          }
  
        def getFormattedNumber(){
         def number = g.formatNumber(number: 5000,234 , type: "number" , maxFractionDigits: 2)
         return number
       }
  }
  </code></pre>
  
  <p>How to do this.</p>