0
0

More than 1 year has passed since last update.

Goで指数表記を取り扱う

Last updated at Posted at 2023-06-10

今年の3月まで19ヶ月ほどGoを書いていたのですが、その際は何となく雰囲気でやっていたので。
Goを基礎から勉強しなおそうと思い、A Tour of Goをやっています。

指数表記のお試しメモ

Pointers to structs1e9を直接指定しているのを見たので調べた所、指数表記というものらしい。
非常に大きな数または非常に小さな数を表現する際に使い、直接指定出来る様子。

package main

import (
	"fmt"
	"reflect"
)

func main() {
	exponentialNotation := 1e+4
	fmt.Println("100000を指数表記で", exponentialNotation)
	
	exponentialNotation = 1e4
	fmt.Println("+を省略も出来る", exponentialNotation)
	fmt.Println("型はfloat64になる", reflect.TypeOf(exponentialNotation))

	exponentialNotation = 1e-4
	fmt.Println("0.0001を指数表記にする場合は-で", exponentialNotation)
}
100000を指数表記で 10000
+を省略も出来る 10000
型はfloat64になる float64
0.0001を指数表記にする場合は-で 0.0001

感想

浮動小数点数の値で似たような表記がされているのを見かけていましたが、指数表記という単語自体は初めて知りました。
11年以上プログラマ兼SEをやってますが、8年くらい前にいた銀行系の案件以外で浮動小数点数を重要視するような案件思い出せませんし、そこまで困ったこともなかったですね…。
プログラミング言語が色々と変わっても業務アプリ系だとなんとなく雰囲気で書けちゃいますが、基礎から勉強するのは大切ですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0