New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created Type attribute for Menu and changed Regex for Price #88
Conversation
…bute and the Price regex
and convertPricetoString()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to rename instances of "address book" in comments to "Rms".
"PHONE_VALIDATION_REGEX" under Price class (possible mistake in naming?)
return priceIndouble; | ||
} | ||
|
||
public String convertPricetoString(double priceIndouble){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be adjusted to convert the double to the correct 2 digits after the dot format
public static final String MESSAGE_PRICE_CONSTRAINTS = "Price should be in SGD and in dollars and cents"; | ||
public static final String PHONE_VALIDATION_REGEX = "\\d+";//"^\\$\\d+([.][0-9]+)?$"; | ||
public static final String PHONE_VALIDATION_REGEX = "\\$[1-9][0-9]*(\\.[0-9]{2})?|\\$0?\\.[0-9][0-9]";//"^\\$\\d+([.][0-9]+)?$"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRICE_VALIDATION_REGEX can be adjusted to accept price with only one digit after the dot
builder.append(getPrice()); | ||
return builder.toString(); | ||
} | ||
|
||
/** | ||
* Formats a menu item as text, showing only non-private contact details. | ||
*/ | ||
default String getAsTextHidePrivate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should merge getAsTextShowAll()
and getAsTextShowPrivate()
into one single method getAsText()
…wn to 2 decimal place if there are more than 2 decimal digits in the priceIndouble variable
@@ -45,6 +45,11 @@ public static String convertPricetoString(double priceIndouble){ | |||
if((valueAsPrice.substring(decimalIndex)).length()<3){ | |||
valueAsPrice = valueAsPrice + "0"; | |||
} | |||
if((valueAsPrice.substring(decimalIndex)).length()>3){ | |||
priceIndouble = Math.round(priceIndouble*100.0)/100.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of this calculation may create a result of 0 or 1 digit after the dot, which makes the string format not to have exactly 2 digits after the dot.
No description provided.