Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Using FORMAT with both whole numbers and decimals

I feel like I'm missing something obvious, but when using the FORMAT function with custom formats, is there a way to only display decimals when relevant?

 

The behavior I'd like is for the value 5 to be displayed as 5, but 5.5 to be displayed as 5.5 and 5.111 as 5.1

 

At the moment, I have the choice between formatting using "0.0", which displays 5 as 5.0, formatting using "0.#", which displays 5 as "5.", or formatting using "0" which keeps 5 as 5 but rounds the decimal values. I would've expected the behavior of "0.#" to remove the decimal separator when it's not needed but apparently not? Am I just doing something wrong?

  • Anonymous Try this

     

    Formatted column =
    IF( 
    INT( Table8[Column1] ) = Table8[Column1], 
    FORMAT( Table8[Column1] , "#"), 
    FORMAT( Table8[Column1], "#.0" ) 
    )

     

     

2 Replies

  • Anonymous Try this

     

    Formatted column =
    IF( 
    INT( Table8[Column1] ) = Table8[Column1], 
    FORMAT( Table8[Column1] , "#"), 
    FORMAT( Table8[Column1], "#.0" ) 
    )

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      That works, thank you! I didn't realize INT could be used that way.