# To find four-digit numbers after comma

19 views (last 30 days)
Hamza YAPICI on 29 Jan 2020
Commented: Walter Roberson on 29 Jan 2020
Hello,
I am trying to find first 1,2,3,4 digit numbers after the comma in the matrix below. The numbers with more than 4 digit have to be eliminated. How can I find this numbers?
a = [0.0001255 0.0212215 0.20222022 0.9805446;
0.0222 0.2026454 0.0100 0.98052516;
0.0010 0.002 0.1 0.2000;
0.23156498 0.6545648 0.467823 0.9876564];
However, all numbers must be in the same row. For example, a (2, :) should not be selected.
##### 2 CommentsShow 1 older commentHide 1 older comment
Hamza YAPICI on 29 Jan 2020
Edited: Hamza YAPICI on 29 Jan 2020
in my homework:
b = [0.0010 0.0020 0.1000 0.2000]

Walter Roberson on 29 Jan 2020
sprintf('%.99g', 0.0222)
ans =
'0.0222000000000000009825473767932635382749140262603759765625'
*None* of the entries in your matrix are 4 digits after the decimal. MATLAB does not store floating point numbers in decimal, and there is no exact finite binary floating point representation of 0.1. The *only* binary floating point values that are four digits after the decimal point are
0.0625 0.1875 0.3125 0.4375 0.5625 0.6875 0.8125 0.9375
##### 2 CommentsShow 1 older commentHide 1 older comment
Walter Roberson on 29 Jan 2020
This is important! MATLAB does not handle fractions in decimal! Very few programming languages handle fractions in decimal. The only existing commercial implementation of decimal floating point hardware that I know of is the IBM Z9 series.
The values of the 3rd row of the matrix are
0.001000000000000000020816681711721685132943093776702880859375
0.00200000000000000004163336342344337026588618755340576171875
0.1000000000000000055511151231257827021181583404541015625
0.200000000000000011102230246251565404236316680908203125
These are not even remotely close to being 4 digit numbers! More like 60 digit numbers.