Adrian Z.

Adrian Z. IT Project Manager &
PHP Programmer

Temat: json_decode i float

Początkowy kawałek formularza wygląda tak:

var cm_prices = new Ext.grid.ColumnModel(
[
{
id:'price',
header: "Cena",
width: 100,
sortable: true,
align: 'right',
renderer: function(mnt)
{
mnt -= 0;
mnt = (Math.round(mnt*100))/100;
mnt = (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
if (mnt=='0.00')
return '<span style="color:red;">'+mnt+' zł</span>';
else
return mnt+" zł";
},

dataIndex: 'price',
editor: new fm.NumberField(
{
decimalSeparator: ".",
allowBlank: false,
allowNegative: false,
maxValue: 9999
})

},

Następnie ląduje to w

var store_prices = new Ext.data.Store(
{
autoLoad:false,
reader: new Ext.data.JsonReader(
{
fields:
[
{name: 'id', type: 'int'},
{name: 'price',type: 'float'},
{name: 'promotion_price',type: 'float'},
{name: 'packet_price',type: 'float'},
{name: 'promotion_packet_price',type: 'float'},
{name: 'from', type: 'int'},
{name: 'product_id'},
{name: 'price_vat', type: 'int'}
]
}),
url:'index.php/admin_products/index/true/prices'
});

A już w php pozrobieniu

$data=json_decode($this->input->post('data'));

obiekt wygląda tak

object(stdClass)#15 (16) {
["id"]=>
string(5) "16860"
["providers"]=>
array(0) {
}
["prices"]=>
array(1) {
[0]=>
object(stdClass)#13 (6) {
["price"]=>
float(99)
["price_vat"]=>
int(22)
["promotion_price"]=>
int(99)
["packet_price"]=>
int(99)
["promotion_packet_price"]=>
int(99)
["from"]=>
int(10)
}
}

I pytanie jakim cudem po wpisaniu w formularzu "99.99" na wyjściu dostaję float obcięty do int "99" a reszta chociaż też jest float , już całkiem zmienia sięna int .
Łukasz M.

Łukasz M. A co tu trzeba
napisac ?

Temat: json_decode i float

Bo Ty zawsze wymyslasz dziwne kody :D
Adrian Z.

Adrian Z. IT Project Manager &
PHP Programmer

Temat: json_decode i float

Tym razem poprawiam po kimś mądrym, kto napisał sklep internetowy nawet bez VATu :|



Wyślij zaproszenie do