From the course: Learning the Go Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Formatting and precision

Formatting and precision - Go Tutorial

From the course: Learning the Go Standard Library

Start my 1-month free trial

Formatting and precision

- [Instructor] In a previous video we saw how to use formatting verbs to control how various pieces of data were formatted into a string. And for numerical data we can apply even more control over how numbers are represented. So let's go into the formatting folder in the start folder of our sample code, I'm going to open up format_start.go and here in my code I have a floating point number, which I will uncomment. And we're going to try a few different ways of formatting it so let me also uncomment the import for the format function. So to start with a simple example, let's try specifying the number of decimal places for the number. And we do this by using a period followed by the number of decimal places that we want in the precision. So I'll write format.printf and then inside of my formatting string I'm going to write percent and then .2f for a floating point number and then a new line. And then the variable which is F. We…

Contents