diff --git a/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java b/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java index 8289f3f..d482dec 100644 --- a/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java +++ b/app/src/main/java/com/mouseboy/assignment1/MainCalculatorActivity.java @@ -8,8 +8,34 @@ import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; + public class MainCalculatorActivity extends AppCompatActivity { + public static String formatDecimal(double value) { + BigDecimal decimalValue = BigDecimal.valueOf(value); + + String pattern; + + if (decimalValue.stripTrailingZeros().scale() <= 0) { + pattern = "#,##0"; + } else { + pattern = "#,##0.##"; + } + + DecimalFormat df = new DecimalFormat(pattern); + + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + symbols.setGroupingSeparator(','); + + df.setDecimalFormatSymbols(symbols); + + return df.format(value); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/res/drawable/rounded_button.xml b/app/src/main/res/drawable/rounded_button.xml new file mode 100644 index 0000000..819d221 --- /dev/null +++ b/app/src/main/res/drawable/rounded_button.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/activity_main_calculator.xml b/app/src/main/res/layout-land/activity_main_calculator.xml index 9e30ba6..af31b29 100644 --- a/app/src/main/res/layout-land/activity_main_calculator.xml +++ b/app/src/main/res/layout-land/activity_main_calculator.xml @@ -16,6 +16,7 @@ android:clickable="false" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" + app:layout_constraintTop_toTopOf="parent" app:subtitleTextAppearance="@style/TextAppearance.AppCompat.Large"> - - - -