7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでマイナス ゼロが出るときの対処法

Posted at

0÷(負の数)=マイナス ゼロ

Pythonでは0÷負の数の計算を行うと結果が-0.0になります。

n = 0.0/-1
print(n)
# =>-0.0

##対処法
0.0を足すことで-0.0の符号を消すことができます。

n = 0.0/-1
print(n+0.)
# => 0.0

デモ

AOJの問0004でこの現象に遭遇して困った経験があります。
マイナス ゼロで困ってる人の助けになれば幸いです。

7
4
1

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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?