JavaScriptで数値を整数に変換したいとき、真っ先に parseInt() を思い浮かべる人は多いかもしれません。しかし、ここに大いなる罠が潜んでいます。 なんと、parseInt() に「小さすぎる小数」を渡すと、値が勝手に巨大化して返ってくるのです。 実際の挙動を見 ...
こんな風に適当な基数に変換してくれます。 parseInt("0x37") --> 55 parseInt("37") --> 37 問題はここで、 先頭に 0 のあるhogeは 8 進数と判断されて 0 に変換されしまったのです。 parseInt は基数を指定できます。(指定できる値は「2」「8」「10」「16」) ですので ...
Since dates are stored as strings in a certain DB table in a format like"04/01", I want to retrieve them. While checking the operation, something strange happened. When I retrieved the date for August ...
parseFloat() and parseInt() are two essential methods in JavaScript for converting strings to numbers. These methods are particularly useful when dealing with user input or processing data that comes ...
一部の結果でアクセス不可の可能性があるため、非表示になっています。
アクセス不可の結果を表示する