Standard library / strconv
strconv.FormatComplex()
Formats a complex number as parenthesized real and signed imaginary parts; format and precision follow FormatFloat, bitSize is 64 or 128. Expected stdout: '(2.0-3.0i)\n'.
Formal Syntax & Structure
go syntaxgo
func FormatComplex(c complex128, fmt byte, prec, bitSize int) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| c | complex128 | Complex value to encode. |
| fmt | byte | Formatting verb byte such as f, e or g. |
| prec | int | Verb-dependent output precision; -1 selects round-trip precision. |
| bitSize | int | Total complex width, 64 or 128. |
Return Value
string
Encoded representation.
Working Example
Example Snippetgo
package main
import ( "fmt" "strconv")
func main() { fmt.Println(strconv.FormatComplex(2-3i, 'f', 1, 128))}