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) string

Parameters & Attributes

NameTypeDescription
ccomplex128Complex value to encode.
fmtbyteFormatting verb byte such as f, e or g.
precintVerb-dependent output precision; -1 selects round-trip precision.
bitSizeintTotal 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))}
Go Reference