Knowledgebase

Working With Dates, Numbers and Currency Print

  • frontenddevelopment, frontend, woocommerce, guide, howto, solution, zillionkinghost, hosting
  • 0

Formatting and correctness.

WHAT GOES WRONG WITH DATES

Time zones Formats differing by locale Ambiguity between day and month Arithmetic across daylight changes

WHAT TO STORE AND TRANSMIT

A standard unambiguous format, in a single reference time zone.

WHAT TO DISPLAY

The user's local time, formatted for their locale.

WHAT TO USE

The platform's internationalisation facilities, or an established library.

WHAT NOT TO DO

Format dates by joining strings Assume the user's time zone matches the server's

WHAT TO BE CAREFUL WITH

Dates without times, which should not be converted between zones.

WHY

A birth date shifting by a day is a common and confusing bug.

WHAT TO NEVER USE FOR MONEY

Floating point arithmetic.

WHY

It produces rounding errors, visibly.

WHAT TO USE INSTEAD

Integer minor units, or a decimal library.

WHAT TO FORMAT WITH

The platform's number formatting, which handles separators and currency symbols by locale.

WHAT TO DECIDE ONCE

Where rounding happens, and apply it consistently.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot