Skip to content

Instantly share code, notes, and snippets.

@basicmag
Created August 13, 2023 22:12
Show Gist options
  • Save basicmag/36b0ee3d6a5b2ec91a9073ef64d91e4d to your computer and use it in GitHub Desktop.
Save basicmag/36b0ee3d6a5b2ec91a9073ef64d91e4d to your computer and use it in GitHub Desktop.

Revisions

  1. basicmag created this gist Aug 13, 2023.
    30 changes: 30 additions & 0 deletions 010_float4.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    // Go言語 必読本 Essential Go
    // https://www.amazon.co.jp/dp/B0CF53VMYB
    //
    // Go言語: Sscanfを使って文字列をfloatに変換する

    package main

    import (
    "fmt"
    "log"
    )

    func main() {
    s := "1.2341"
    var f float64
    _, err := fmt.Sscanf(s, "%f", &f)
    if err != nil {
    log.Fatalf("fmt.Sscanf failed with '%s'\n", err)
    }
    fmt.Printf("f: %f\n", f)
    }

    // Go言語 必読本 Essential Go
    // https://www.amazon.co.jp/dp/B0CF53VMYB
    //
    // Essential Go
    // https://www.programming-books.io/essential/go/
    // By Krzysztof Kowalczyk
    //
    // Content is licensed under Creative Commons Attribution-ShareAlike 3.0