-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
digit separator added
- Loading branch information
Showing
4 changed files
with
58 additions
and
9 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
47 changes: 47 additions & 0 deletions
47
composeCalculator/src/main/java/ir/wave/composecalculator/Utils/DigitSeprator.java
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,47 @@ | ||
package ir.wave.composecalculator.Utils; | ||
|
||
public class DigitSeprator { | ||
|
||
|
||
public static String seRaghmBandi(String Orgprice) { | ||
return NRaghmBandi(Orgprice, true, 3); | ||
} | ||
|
||
//if after Number is Persian Text manfiInEnd must true | ||
public static String seRaghmBandi(String Orgprice, boolean manfiInEnd) { | ||
return NRaghmBandi(Orgprice, manfiInEnd, 3); | ||
} | ||
|
||
public static String NRaghmBandi(String Orgprice, boolean manfiInEnd, int nRaghami) { | ||
String price; | ||
String Ashar = ""; | ||
boolean cntManfi = false; | ||
if (Orgprice.contains("-")) { | ||
cntManfi = true; | ||
Orgprice = Orgprice.replace("-", ""); | ||
} | ||
if (Orgprice.contains(".")) { | ||
price = Orgprice.substring(0, Orgprice.indexOf(".")); | ||
Ashar = Orgprice.substring(Orgprice.indexOf(".")); | ||
} else price = Orgprice; | ||
|
||
StringBuilder s = new StringBuilder(price); | ||
for (int i = s.length() - nRaghami; i > 0; i -= nRaghami) { | ||
s.insert(i, ","); | ||
} | ||
if (cntManfi) | ||
return manfiInEnd ? (s + Ashar + "-") : ("-" + s + Ashar); | ||
else | ||
return s + Ashar; | ||
} | ||
|
||
public static String AsharDasti(String mS) { | ||
String f = mS; | ||
if (mS.length() == 0 || !mS.contains(".") || (mS.contains(".") && mS.indexOf(".") == mS.length() - 1)) | ||
return mS; | ||
else if (mS.length() - 1 - mS.indexOf(".") > 3) | ||
f = mS.substring(0, mS.indexOf(".") + 4); | ||
return f; | ||
} | ||
|
||
} |