Skip to content

Commit

Permalink
Change price to have only 2 decimal digits
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Spektor committed Feb 16, 2016
1 parent 88ff1ea commit 016c04e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions SoomlaAndroidStore/src/com/soomla/store/domain/MarketItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class MarketItem {
/**
* Constructor.
*
* @param mProductId the id of the current item in the market
* @param mPrice the actual $$ cost of the current item in the market
* @param productId the id of the current item in the market
* @param price the actual $$ cost of the current item in the market
*/
public MarketItem(String mProductId, double mPrice) {
this.mProductId = mProductId;
this.mPrice = mPrice;
public MarketItem(String productId, double price) {
this.mProductId = productId;
setPrice(price);
}

/**
Expand All @@ -54,7 +54,7 @@ public MarketItem(JSONObject jsonObject) throws JSONException {
} else {
this.mProductId = jsonObject.getString(StoreJSONConsts.MARKETITEM_PRODUCT_ID);
}
this.mPrice = jsonObject.getDouble(StoreJSONConsts.MARKETITEM_PRICE);
setPrice(jsonObject.getDouble(StoreJSONConsts.MARKETITEM_PRICE));

this.mMarketPriceAndCurrency = jsonObject.optString(StoreJSONConsts.MARKETITEM_MARKETPRICE);
this.mMarketTitle = jsonObject.optString(StoreJSONConsts.MARKETITEM_MARKETTITLE);
Expand All @@ -74,7 +74,7 @@ public JSONObject toJSONObject(){
jsonObject.put(JSONConsts.SOOM_CLASSNAME, SoomlaUtils.getClassName(this));

jsonObject.put(StoreJSONConsts.MARKETITEM_ANDROID_ID, mProductId);
jsonObject.put(StoreJSONConsts.MARKETITEM_PRICE, Double.valueOf(mPrice));
jsonObject.put(StoreJSONConsts.MARKETITEM_PRICE, Double.valueOf(getPrice()));

jsonObject.put(StoreJSONConsts.MARKETITEM_MARKETPRICE, mMarketPriceAndCurrency);
jsonObject.put(StoreJSONConsts.MARKETITEM_MARKETTITLE, mMarketTitle);
Expand Down Expand Up @@ -106,6 +106,10 @@ public double getPrice() {
return mPrice;
}

public void setPrice(double price) {
mPrice = Math.round(price * 100) / 100.0;
}


/** Realtime Infomation from the Google Play Store **/

Expand Down

0 comments on commit 016c04e

Please sign in to comment.