2014-06-10 102 views
0



我試圖在Smarty環境中顯示double變量,將其轉換爲int在Smarty中將對象轉換爲int int

配置變量的文件具有以下代碼。 變量PRODUCTS_Quantity_x是我添加的查看變量。它給了我一個逗號分隔的值與3個小數位。 {$module_data.PRODUCTS_Quantity}已經能夠通過html顯示。 像數()等。我已經tryed的事情,我主要是有一個空的變量或Smarty的錯誤...

  $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> 

我希望你能幫助我在這裏 在此先感謝

回答

0

你可以做到這一點2路:

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>