You would have the same problem with any programming language.
Except COBOL or PL/SQL or bc or ...
The problem is related to how numbers are implemented on computers
rather than how any particular language behaves.
Not "number implemented on computers" in general, but specific
implementations of numbers. Binary floating point numbers are very
common (because almost all modern processors support them in hardware)
but there are many other possible number implementations.
Decimal fixed or floating point numbers avoid the problem for decimal
fractions, which is sufficient for applications which need to represent
decimal fractions exactly (e.g. financial applications), but they still
have the problem for other fractions (1/3, 1/7, ...).
Rational numbers can be stored as a pair of (potentially big) integers.
There is no way to represent all numbers in a finite amount of memory of
course.
The number representation is not completely independent of the language.
C for example mandates that float, double, etc. are floating point
numbers. They can be binary, decimal or use some other base, but they
can't be fractions, for example.
COBOL provides decimal fixed point data types.
PL/SQL has a decimal floating point type (with 38 digits).
bc has arbitrary precision fixed point numbers.
Perl provides several number representations as modules.
hp