PHP使用十进制乘以货币变量

时间:2017-09-22 16:47:13

标签: php

我正在尝试将变量乘以小数(百分比),但它输出0作为值。该变量有一个美元符号和两个小数位($ 53,900.00)。

$baseprice = $53,900.00;
$ott = .92;
echo ($baseprice * $ott);

我认为货币符号($)正在弄乱它。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:2)

您还可以使用money_format()函数以美元符号和逗号将其打印出来。但是当你将一个变量声明为数字时,它不能包含逗号','或'$',否则它会被转换为字符串。以下是使用money_format的示例。

private string GetItemData(string itemID)
{

    var request = (HttpWebRequest)WebRequest.Create("http://open.api.ebay.com/shopping");
    byte[] bytes = null;
    request.Headers.Add("X-EBAY-API-APP-ID", "KavinHim-BestProd-PRD-78e3e6bf1-97d9ef25");
    request.Headers.Add("X-EBAY-API-DEV-NAME", "afd260f4-ec61-49e9-a78e-235d6a622c08");
    request.Headers.Add("X-EBAY-API-CERT-NAME", "PRD-8e3e6bf1d032-6b7b-44e2-abf5-e1a5");
    request.Headers.Add("X-EBAY-API-SITE-ID", "0");
    request.Headers.Add("X-EBAY-API-CALL-NAME", "GetMultipleItems");
    request.Headers.Add("X-EBAY-API-VERSION", "863");
    request.Headers.Add("X-EBAY-API-REQUEST-ENCODING", "xml");


    request.Timeout = Timeout.Infinite;
    request.KeepAlive = true;

    string itemNode = "<ItemID>" + itemID + "</ItemID> \n";

    bytes = System.Text.Encoding.ASCII.GetBytes("<?xml version='1.0' encoding='utf-8'?> <GetMultipleItemsRequest xmlns='urn:ebay:apis:eBLBaseComponents'> <IncludeSelector>ItemSpecifics</IncludeSelector> " + itemNode + " </GetMultipleItemsRequest>");

    request.Method = "POST";
    request.Proxy = null;


    Stream requestStream = request.GetRequestStream();
    requestStream.Write(bytes, 0, bytes.Length);
    requestStream.Close();
    using (var response = (HttpWebResponse)request.GetResponse())
    {
        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream responseStream = response.GetResponseStream();
            string responseStr = new StreamReader(responseStream).ReadToEnd();
            responseStream.Close();
            //var document = XDocument.Parse(responseStr);
            //XNamespace ns = "urn:ebay:apis:eBLBaseComponents";
            return responseStr;

        }
        return null;
    }
}

答案 1 :(得分:1)

您还需要删除逗号

Object