Hallo,
0,25 = 1/4
0.3333.... (Periode) = 1/3
Diese und andere Zuordnungen weiß ich noch aus der Schule.
Gibt es aber eine allgemeine Möglichkeit eine beliebiege Dezimalzahl
(endlich oder periodish) in eine Bruchzahl umzuwandeln, Beispiel
0,34722222222222222222...... = ?
Gruß
Gerrit
Eine Möglichkeit wäre folgende:
float result = 0.0f, compare = 0.347222222f;
for(float x = 0.05f; x < 100.0f; x += 0.01f) {
for(float y = 0.05f; y < 100.0f; y += 0.01f) {
result = x / y;
if(result == compare) {
printf("%f / %f = %f", x, y, compare);
break;
}
}
}
Allerdings nicht sehr schön ...
oma