在Smarty中将double转换为int

时间:2014-06-10 18:44:54

标签: php html casting smarty



我试图在Smarty环境中显示double变量,将其转换为int

配置变量的文件具有以下代码。 变量PRODUCTS_Quantity_x是我添加的已查看变量。它给我一个逗号分隔值,带有3个小数位。 {$module_data.PRODUCTS_Quantity}已经能够通过html显示出来。 我已经尝试了像count()等的东西。我主要得到一个空变量或聪明的错误......

            $t_data_array = array ( 'PRODUCTS_NAME'                     => htmlspecialchars_wrapper($array['products_name']),
                            'COUNT'                             => $array['ID'],
                            'PRODUCTS_ID'                       => $array['products_id'],
                            'PRODUCTS_VPE'                      => $this->getVPEtext($array, $products_price['plain']),
                            'PRODUCTS_IMAGE'                    => $this->productImage($array['products_image'], $image),
                            'PRODUCTS_IMAGE_W'                  => $array['products_image_w'],
                            'PRODUCTS_IMAGE_H'                  => $array['products_image_h'],
                            'PRODUCTS_IMAGE_WIDTH'              => PRODUCT_IMAGE_THUMBNAIL_WIDTH,
                            'PRODUCTS_IMAGE_PADDING'            => ((PRODUCT_IMAGE_THUMBNAIL_HEIGHT + 8) - $array['products_image_h'])/2,
                            'PRODUCTS_IMAGE_ALT'                => $array['gm_alt_text'],
                            'PRODUCTS_LINK'                     => $gm_product_link,
                            'PRODUCTS_PRICE'                    => $products_price['formated'],
                            'PRODUCTS_TAX_INFO'                 => $gm_tax_info,
                            'PRODUCTS_SHIPPING_LINK'            => $gm_shipping_link,
                            'PRODUCTS_BUTTON_BUY_NOW'           => $buy_now,
                            'GM_PRODUCTS_BUTTON_BUY_NOW_URL'    => $gm_buy_now_url,
                            'GM_PRODUCTS_BUTTON_BUY_NOW'        => $gm_buy_now, 
                            'PRODUCTS_SHIPPING_NAME'            => $shipping_status_name,
                            'PRODUCTS_SHIPPING_IMAGE'           => $shipping_status_image,
                            'PRODUCTS_DESCRIPTION'              => $array['products_description'],
                            'PRODUCTS_EXPIRES'                  => $array['expires_date'],
                            'PRODUCTS_CATEGORY_URL'             => $array['cat_url'],
                            'PRODUCTS_SHORT_DESCRIPTION'        => $array['products_short_description'],
                            'PRODUCTS_FSK18'                    => $array['products_fsk18'],
                            'GM_FORM_ACTION'                    => xtc_draw_form('gm_add_to_cart_'.$array['products_id'], xtc_href_link('index.php', 'action=buy_now&BUYproducts_id=' . $array['products_id'] . $gm_cat_search, 'NONSSL', true, true, true), 'post', 'onsubmit="return gm_quantity_check_listing(\'' . $array['products_id'] . '\')"'),
                            'FORM_DATA'                         => $t_form_array,
                            'QTY_DATA'                          => $t_qty_array,
                            'PRODUCTS_Quantity_x'               => $array['products_quantity'],  
                            'GM_FORM_END'                       => '</form>',
                            'GM_PRODUCTS_QTY'                   => $gm_qty,
                            'GM_PRODUCTS_STOCK'                 => $gm_products_stock,
                            'PRODUCTS_META_DESCRIPTION'         => $array['products_meta_description'],
                            'PRODUCTS_WEIGHT'                   => gm_prepare_number((double)$array['products_weight'], $xtPrice->currencies[$xtPrice->actualCurr]['decimal_point']),
                            'SHOW_PRODUCTS_WEIGHT'              => $array['gm_show_weight']);


    return $t_data_array;
    // EOF GM_MOD


在html中,给出了以下代码

    <span class="label">{$module_data.PRODUCTS_Quantity_x}<span>

我希望你能在这里帮助我 提前谢谢

1 个答案:

答案 0 :(得分:0)

你可以这样做:

1)第一种方式:

您可以在Smarty中使用以下代码添加string_format

<span class="label">{$module_data.PRODUCTS_Quantity_x|string_format:"%d"}<span>

2)第二种方式:

您可以在PHP中执行任何操作,并在PHP中分配所需的值。

所以在PHP中你可以换行:

'PRODUCTS_Quantity_x'=> $array['products_quantity'],

'PRODUCTS_Quantity_x'=> (int) $array['products_quantity'],

然后在Smarty中使用与之前使用的相同的代码(没有string_format):

<span class="label">{$module_data.PRODUCTS_Quantity_x}<span>