taste of ink
Threadersteller
Dabei seit: 14.06.2005
Ort: Hamburg
Alter: 27
Geschlecht:
|
Verfasst Do 02.03.2006 11:52
Titel [PHP, MySQL] Fließkommazahlen speichern - how to? |
 |
|
Ich habe ein kleines Problem in einem PHP-Projekt. Ich möchte ein paar Rechnungen durchführen und am Ende Preise zurück geben. Dabei muss ich ein Paar Fließkommazahlen in eine Datenbank speichern.
Beispiel
123,45 --> 123,00
67,89 --> 67,00
Wie kann ich die richtig speichern? Wenn ich die Variablen mit echo ausgebe haben sie noch 2 Stellen hintern komma, sobald ich speicher haben sie immer 2 Nullen hinterm Komma
MySQL-Tabelle
| Code: |
CREATE TABLE anfragen (
id int(11) NOT NULL auto_increment,
kdnr int(11) DEFAULT '0' NOT NULL,
wunschtermin date DEFAULT '0000-00-00' NOT NULL,
maskenr int(11) DEFAULT '0' NOT NULL,
status int(11) DEFAULT '0',
p1 float(10,2) DEFAULT '0.00' NOT NULL,
p3 float(10,2) DEFAULT '0.00' NOT NULL,
p5 float(10,2) DEFAULT '0.00' NOT NULL,
pn float(10,2) DEFAULT '0.00' NOT NULL,
w1 float(5,2) DEFAULT '0.00' NOT NULL,
w2 float(5,2) DEFAULT '0.00' NOT NULL,
w3 float(5,2) DEFAULT '0.00' NOT NULL,
w4 float(5,2) DEFAULT '0.00' NOT NULL,
w5 float(5,2) DEFAULT '0.00' NOT NULL,
w6 float(5,2) DEFAULT '0.00' NOT NULL,
w7 float(5,2) DEFAULT '0.00' NOT NULL,
w8 float(5,2) DEFAULT '0.00' NOT NULL,
w9 float(5,2) DEFAULT '0.00' NOT NULL,
w10 float(5,2) DEFAULT '0.00' NOT NULL,
w11 float(5,2) DEFAULT '0.00' NOT NULL,
w12 float(5,2) DEFAULT '0.00' NOT NULL,
w13 float(5,2) DEFAULT '0.00' NOT NULL,
w14 float(5,2) DEFAULT '0.00' NOT NULL,
w15 float(5,2) DEFAULT '0.00' NOT NULL,
w16 float(5,2) DEFAULT '0.00' NOT NULL,
w17 float(5,2) DEFAULT '0.00' NOT NULL,
w18 float(5,2) DEFAULT '0.00' NOT NULL,
w19 float(5,2) DEFAULT '0.00' NOT NULL,
w20 float(5,2) DEFAULT '0.00' NOT NULL,
w21 float(5,2) DEFAULT '0.00' NOT NULL,
w22 float(5,2) DEFAULT '0.00' NOT NULL,
w23 float(5,2) DEFAULT '0.00' NOT NULL,
w24 float(5,2) DEFAULT '0.00' NOT NULL,
w25 float(5,2) DEFAULT '0.00' NOT NULL,
w26 float(5,2) DEFAULT '0.00' NOT NULL,
w27 float(5,2) DEFAULT '0.00' NOT NULL,
w28 float(5,2) DEFAULT '0.00' NOT NULL,
w29 float(5,2) DEFAULT '0.00' NOT NULL,
w30 float(5,2) DEFAULT '0.00' NOT NULL,
PRIMARY KEY (id)
)
|
PHP-Befehl
| Code: |
if(!$fehler AND $_GET[kalkulieren])
{
$tabellenname="anfragen";
include('/connect.php');
$sql="INSERT INTO ".$tabellenname."(kdnr,maskenr,status,w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14) values
(123456,1,1,".$_GET[bohrung].",".$_GET[luftflaechen].",".$_GET[ausrichtflaechen].",1,".$_GET[kontrolle].",".$_GET[beschichtung].",
".$_GET[material2].",".$_GET[material_zw].",".$_GET[material_arm].",".$_GET[laenge].",".$_GET[klaenge].",".$_GET[d1].",".$_GET[d2].",
".$_GET[khoehe].")";
if(!mysql_query($sql, $link)){$db_fehler=="<br><p style=\"color:red\">Datenbankfehler:<br>".mysql_error()."<br></p>";}
}
|
|
|