pry(main)> time = Time.now
=> 2012-01-20 00:10:44 +0000
pry(main)> (time + 4.days).to_f
=> 1327363844.9709609
pry(main)> time.to_f
=> 1327018244.970961
Why does adding a day to a time change the fractional part of seconds?
306 Views Asked by Peder At
2
There are 2 best solutions below
0
MRocklin
On
This is a floating point rounding issue. Your number is stored as a double precision floating point number which has a precision of 53 bits. 2^53 is roughly 9*10^15 giving you between 15 and 16 decimal digits, depending on the exact number to be represented.
You may notice that these two numbers have 16 and 15 decimal digits respectively. You are off only in the last place. In truth the exact stored value is neither of these two decimal numbers but rather something that is only exactly represented in fractional binary.
Related Questions in RUBY
- how to integrate cashfree payment gateway in ruby on rails project
- RSpec Capybara throwing Selenium error when trying to click a button with browser confirm
- Duplicate GET requests - Rails & Heroku
- convert csv file with json data inside to a column, rows table in 2nd csv file
- Installing dependencies from a gemspec file
- Verifying Google Identity OAuth2 token with Ruby
- Java code of AES/GCM/NoPadding encryption algorithm with authentication tag
- How to fix error in model with gem lockbox
- Cannot install Ruby Gem on Window
- use logstash filter ,aes gcm encrypted in ruby,but cannot decrypted in java
- In Rails 7, what is the right ActiveRecord callback to use if I need to prevent (or rollback) persistance on error?
- How can I go through an array and still remove elements from it
- Nokogiri only returning 5 results
- How do I get the fullscreen mode in firefox?
- undefined group option when using branch reset group regex in Ruby
Related Questions in DATETIME
- I wrote this time displaying FLUTTER app, How can I improve it?
- How to convert pandas series to integer for use in datetime.fromisocalendar
- JSON file of 7000 meetings in multiple timezones and Flatlist
- Intl.DateTimeFormat() - return weekday as number?
- I'd like to create a custom time zone converter, any pointers?
- How set weekday datetime?
- ValueError: setting an array element with a sequence. Trying to make a Skymap in Python
- Different X axes with Plotly's make_subplots
- Error when converting datetime from UTC to Brasilia datetime in Power BI
- Problem converting time series df from chr to date using as.POSIXct
- How to supress naive datetime warning in django
- How to find rows that fall within time range from a dataframe?
- Timedelta error - AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
- How to convert "Tue Feb 27 2024 16:35:30 GMT+0800" String to ZonedDateTime type
- react apex charts x axis labels and tool tip showing different times instead of actual PST time
Related Questions in DATE
- Using JQuery Date Slider
- Get Type Error when using .countDocuments with mongoDB
- Gsheet - Automatically send an email using a date & time in a Cell
- Market share growth versus last month, last year
- Convert date string into a number in Python
- Date formatting "yyyy-MM-dd hh:mm:ss +0000" to "dd MMM" in swift
- How does Big Query differentiate between a day and month when we upload any CSV or text file?
- Event_date reference in CTE
- Laravel Nova 4 format date in BelongsTo field
- how to count days elpased between each interval using mySQL?
- MariaDB incorrect dates
- Date issue - how do I parse date in this SQL
- Countdown to varying payday in Javascript
- Can I have a static ISO8601DateFormatter with specific formatOptions in Swift?
- Date Format mdy vs dmy
Related Questions in DATETIME-FORMAT
- How to get just the time zone name from Intl.DateTimeFormat?
- How can I use pandas.DataFrame.to_csv to write pandas.Timestamp with milliseconds?
- How to set datetime format in jquery datetimepicker?
- How to properly parse Buddhist year in MongoDB?
- What is the correct way to write date-time in ISO 8601 format when milliseconds has less than 3 digits?
- How to write/read std::chrono::zoned_seconds to/from a stream using chrono::parse?
- can i convert float to datetime using python?
- Error converting strimg column to timestamp in BigQuery
- How to show 00:00 (24hrs format) for 12am instead 24:00 in flutter
- How to import excel with timestamp correctly into dataframe (pandas)
- Datetime format changing and averaging to 15 minutes
- Date conversion issue in pipeline
- Time formatting in c++
- converting startDatetime to localtime using UTC timezone
- Formula to identify where there is a value for '0' and '1' per date in Excel pivot table
Related Questions in SECONDS
- LibreOffice Calc SECOND function returning wrong value - why?
- Countif rows are within 1,000 milliseconds or 1 second
- AnimatedContainer duration property does not effect the animation of container in Flutter
- In a DOS dir, list timedate of files including seconds (in the format "hh:mm:ss" instead of "hh:mm")
- Lookback that calculates differently depending on chart time being viewed
- Seconds and scale_x_time - HH:MM instead of HH:MM:SS
- VHDL Pulse counter in one second and in one minute
- How to preform correct delay system using TIMER_A on the TEXAS MSP432?
- Casting double chrono::seconds into millisecond
- set local time from timezone offset in seconds
- Google Sheets: How to Convert Column Values In mmm:ss or mm:ss Format to Minutes
- PHP Laravel - Finding the quantity of seconds in each hour between two timestamps
- When save an Excel to csv, the seconds automatically become 0?
- New column to display DD HH:MM:SS from column of total second
- Ignore seconds portion of TIMESTAMP field in query selection WHERE clause
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
It didn't for me when I did:
I believe this is just a small round issue common with floats and you found a small precision error.
That is much less than a second, i.e. .0000001 of a day. Given there are only 86,400 seconds in a day this is frequently not a issue, although a good reason to store dates as dates and do Ruby date arithmetic on them.