-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add usd equivalent balance to overview page
- Loading branch information
Showing
11 changed files
with
197 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2018-2019 The Decred developers | ||
* Use of this source code is governed by an ISC | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package com.dcrandroid.util | ||
|
||
import java.math.BigDecimal | ||
import java.math.RoundingMode | ||
import java.text.DecimalFormat | ||
|
||
val usdAmountFormat: DecimalFormat = DecimalFormat("###,###,###,###,###.####") | ||
val usdAmountFormat2: DecimalFormat = DecimalFormat("###,###,###,###,###.##") | ||
|
||
object CurrencyUtil { | ||
fun dcrToFormattedUSD(exchangeDecimal: BigDecimal?, dcr: Double, scale: Int = 4): String { | ||
if (scale == 4) { | ||
return usdAmountFormat.format( | ||
dcrToUSD(exchangeDecimal, dcr)!!.setScale(scale, BigDecimal.ROUND_HALF_EVEN).toDouble()) | ||
} | ||
return usdAmountFormat2.format( | ||
dcrToUSD(exchangeDecimal, dcr)!!.setScale(scale, BigDecimal.ROUND_HALF_EVEN).toDouble()) | ||
} | ||
|
||
fun dcrToUSD(exchangeDecimal: BigDecimal?, dcr: Double): BigDecimal? { | ||
val dcrDecimal = BigDecimal(dcr) | ||
return exchangeDecimal?.multiply(dcrDecimal) | ||
} | ||
|
||
fun usdToDCR(exchangeDecimal: BigDecimal?, usd: Double): BigDecimal? { | ||
if (exchangeDecimal == null) { | ||
return null | ||
} | ||
|
||
val usdDecimal = BigDecimal(usd) | ||
// using 8 to be safe | ||
return usdDecimal.divide(exchangeDecimal, 8, RoundingMode.HALF_EVEN) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > | ||
<corners android:radius="8dp"/> | ||
<!-- <solid android:color="@android:color/white" />--> | ||
<stroke android:width="1dip" android:color="#8997A5"/> | ||
</shape> |
Oops, something went wrong.