Assuming the OPs native language is German:

Lieber Freund, Du hast kein Problem mit der Speicherung sondern mit der 
Darstellung der Werte.

MySQL übernimmt aufgrund der Typangabe "decimal(7,4)" die 
Darstellung/Formatierung der Werte. Vor dem Speichern wird der Wert so 
skaliert, dass immer ganzzahlige Werte entstehen, im konkreten Fall also mal 
10000. Aus dem Wert 1.5 wird so 15000. Bei der Anzeige wird der gespeicherte 
Wert durch den Skalierungsfaktor dividiert und an der entsprechenden Stelle ein 
Dezimalpunkt eingefügt.

SQLite hat keinen Typ "decimal". Daher musst Du in Deiner Anwendung diese 
Umrechnung selbst durchführen. Also vor dem speichern mit 10000 multiplizieren 
und nach dem lesen durch 10000 dividieren.

Da ist keine Hexerei im Spiel. Man muss nur sauber zwischen Wert und 
Darstellung/Formatierung trennen.

Wenn man für mehrere Plattformen mit unterschiedlichen eingebauten 
Funktionalitäten programmiert, dann muss man entweder eine Abstraktionsebene 
einführen, die die Unterschiede verbirgt (d.h. konkret die 
Umrechnung/Formatierung selbst programmieren, falls SQLite als Datenbank 
benutzt wird), oder aber nur die gemeinsamen, auf beiden Plattformen 
verfügbaren Funktionalitäten benutzen (d.h. konkret das Datenmodell in mySQL 
ändern und für beide Fälle immer selbst umrechnen).

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von Werner Kleiner
Gesendet: Freitag, 02. Dezember 2016 13:01
An: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
Betreff: *** suspected spam or bulk *** Re: [sqlite] Datatype for prices (1,500)

@Darren,

my "problem" is, that the both trailing zeros 00 after 1.5 are missing in 
sqlite In MySQL the price is stored as 1.500

I do not undestand exact what you mean with multiply the number?

If I multiply 1.5 x 10000 with PHP before storing in sqlite then I get 15000?

best regards
Werner

2016-12-01 11:46 GMT+01:00 Darren Duncan <dar...@darrenduncan.net>:
> Look, you want to store the same level of detail that a decimal(7,4) does?
>
> Easy, you just multiply the conceptual number by 10,000 and it
> represents hundredths of a cent, the exact same precision you are using in 
> MySQL.
>
> Your examples would then be stored as 20 or 8 respectively.  And every
> other possible value you could store in the MySQL you can now store in
> SQLite, consistently.
>
> -- Darren Duncan
>
> On 2016-12-01 12:08 AM, Werner Kleiner wrote:
>>
>> As I can see storing prices is a topic with different ways and
>> different solutions.
>>
>> The advice to store prices in Cent or Integer:
>> Yes you can do: but how will you sore hundredth cents amounts or
>> tenth cent prices?
>> I have prices like 0,0020 or 0,0008 Euro
>>
>> I think I have to manipulate the prices for viewing in the app with PHP.
>> Fact is: we can have to DBs MySQL and SQlite. MySQL with decimal(7,4)
>> stores a price 1.500 from a textfield exact so.
>> If you want to show the price again in the app, there is nothing to do.
>> But switching to SQLite the price is viewed as 1.5 (and stored) I
>> know this is no error of SQLite. But I have now to differ between
>> Sqlite and MySQL and have to optimize the SELECT and adding 00
>> programmatically to view correct if using Sqlite.
>>
>> My original post was if there is a way for both DBs with same
>> behavior, but it seems not.
>>
>> Thanks to all for help.
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: h...@scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to