Bitcoin Forum
November 14, 2024, 11:38:53 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: The best way to store and use currencies (PHP+MYSQL)  (Read 415 times)
glorsh66 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
July 20, 2017, 07:14:52 PM
 #1

I am developing a non profit project that uses a lot of forks (and bitcoin of course) - but's i can't decide what datatype use to store prices.
There are several ways to do this, but i have chosen two of them - to use BIGINTEGER, and store it as a STRING

1) - BIGINTEGER (in this case i keep pennie e.g. Satoshi) it's better to use in calculations - but i can't wrap my head around - how to properly take user input? What datatype should i use to use math operations in PHP, and what additional data i need to keep to convert on currency to another (i mean there are possibility that some forks can use more digits after point.)
2) STRING - just impossible to make any computations, before proper conversion. But it's much simper to keep - i mean you just can store the raw user's input   

Can somebody share some ideas with me about this matter?
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
July 20, 2017, 07:35:55 PM
 #2

I am developing a non profit project that uses a lot of forks (and bitcoin of course) - but's i can't decide what datatype use to store prices.
There are several ways to do this, but i have chosen two of them - to use BIGINTEGER, and store it as a STRING

1) - BIGINTEGER (in this case i keep pennie e.g. Satoshi) it's better to use in calculations - but i can't wrap my head around - how to properly take user input? What datatype should i use to use math operations in PHP, and what additional data i need to keep to convert on currency to another (i mean there are possibility that some forks can use more digits after point.)
2) STRING - just impossible to make any computations, before proper conversion. But it's much simper to keep - i mean you just can store the raw user's input   

Can somebody share some ideas with me about this matter?

An inneficient way of doing this is by you just using strings for everything. There is only addition and subtraction that is required in this I presume, so you can easily just encorporate math in that way.
Alternatively, you could try to use "Double" variable types or "Float" if php doesn't provide "double"s (doubles is with a desimal but is 64 bit floating point instead of 32 bit.
I assum BIGINTEGER represents INT64, but you could as well just use regular integers as they should be 232 and you probably don't need much higher than that.
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
July 21, 2017, 07:30:14 AM
 #3

I'm using DECIMAL for storing values, and so far that worked fine with calculations in SQL.
If you want to do math in PHP, you should look at BCMath.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!