Help with number format [SOLVED]

Hey there, I’m trying to format a number like… For example if it’s 26.63, I need the output to be 26.6… If the number is 8.45, I need to show 8.4, and if it’s “0”, display 0.0… I’m doing like the following;

fmt.Sprintf("%2.1f", 26.636)

The above example works and displays the expected result, but if I try to format a 0 number like;

fmt.Sprintf("%2.1f", 0)

It displays smth like; %!f(int= 0)

Anyone know where is the error?


You’re giving a format for a float, but passing an integer constant. Try 0.0 or a float variable.

1 Like

Thanks @calmh Jakob.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.