タマニチェンコさんのブログ

最新一覧へ

« 前へ43件目 / 全239件次へ »
ブログ

ScalaのDouble

Scalaで小数点以下1位で四捨五入したくて色々試した。


scala> 1 / 1
res11: Int = 1

scala> 10 / (3 * 1.0)
res4: Double = 3.3333333333333335

scala> (10 / (3 * 1.0)).round
res5: Long = 3

scala> (10 / (3 * 1.0)).round(1)
:6: error: scala.this.Predef.doubleWrapper(3.3333333333333335).round of
type Long does not take parameters
(10 / (3 * 1.0)).round(1)
^

scala> (20 / (3 * 1.0)).round
res7: Long = 7

scala> (20 / (3 * 1.0)).floor
res8: Double = 6.0

scala> (20 / (3 * 10.0)).floor / 10
res9: Double = 0.0

scala> (20 *10 / (3 * 1.0)).floor / 10
res10: Double = 6.6
コメントを書く
コメントを投稿するには、ログイン(無料会員登録)が必要です。