0

朝、

データベースから2つの価格を追加して、1つの価格を作成する方法を知りたいです。私の現在のコードは以下の通りです。

 orderPriceTotal = oi.price + oi.shippingPrice,

すべての助けは大歓迎です、ありがとう:)

4

2 に答える 2

0

If oi.price and oi.shippingPrice are numeric (hopefully decimal) values then what you have should just work.

If they are already strings then go back to the data source and return them as decimal values.

If you can't do that then you'll need to convert them back to numerical values, add them and then convert back into a string.

System.Globalization.CultureInfo culture = <your culture>;
decimal price;
if (decimal.TryParse(oi.price, NumberStyles.Currency, culture, out price);

The NumberStyles.Currency will allow you to parse a string that might contain a currency symbol.

Do the same for shippingPrice then:

orderPriceTotal = (price + shippingPrice).ToString("C", culture);

to convert back to a string complete with the correct currency symbol.

于 2012-07-20T10:11:51.923 に答える
0

動作するはずですが、これらが数値でない場合は、最初に数値に変換してから加算する必要があると思います。

于 2012-07-20T10:21:46.103 に答える