-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remap coins.json for CryptocurrencyTool
Add ScientificNotationParser tool
- Loading branch information
Showing
7 changed files
with
209 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
35 changes: 0 additions & 35 deletions
35
src/main/java/com/tecknobit/apimanager/Tools/Formatters/NumberFormatter.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/main/java/com/tecknobit/apimanager/Tools/Formatters/ScientificNotationParser.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,67 @@ | ||
package com.tecknobit.apimanager.Tools.Formatters; | ||
|
||
import static java.lang.Integer.parseInt; | ||
import static java.lang.String.valueOf; | ||
|
||
/** | ||
* The {@code ScientificNotationParser} class is a useful class tool to get a numeric value without scientific notation | ||
* @author Tecknobit N7ghtm4r3 | ||
* **/ | ||
|
||
public abstract class ScientificNotationParser { | ||
|
||
/** Method to parse a numeric value and format without scientific notation | ||
* @param value: value to fetch without scientific notation | ||
* @return value as {@link String} (es.) 9.2221111228E-6 -> 0.0000092221111228 | ||
* **/ | ||
public static String sNotationParse(Number value){ | ||
if(value == null) | ||
throw new IllegalArgumentException("Value cannot be null"); | ||
if(!(value instanceof Integer)) { | ||
String number = valueOf(value); | ||
if(number.contains("E")) { | ||
int zeroCounter = parseInt(number.split("-")[1]); | ||
return "0." + "0".repeat(zeroCounter - 1) + "" + valueOf((double)value * Math.pow(10, zeroCounter)) | ||
.replace(".", ""); | ||
}else { | ||
int integers = number.split("\\.")[0].length(); | ||
return sNotationParse(integers, (((number.length()) - integers) - 1), value); | ||
} | ||
} | ||
return valueOf(value); | ||
} | ||
|
||
/** Method to parse a numeric value and format without scientific notation | ||
* @param decimals: number of digits after comma | ||
* @param value: value to fetch without scientific notation | ||
* @return value as {@link String} (es.) 9.2221111228E-6 -> 0.0000092221111228 | ||
* **/ | ||
public static String sNotationParse(int decimals, Number value){ | ||
if(decimals < 0) | ||
throw new IllegalArgumentException("Decimals digits value must be positive"); | ||
if(value == null) | ||
throw new IllegalArgumentException("Value cannot be null"); | ||
if(!(value instanceof Integer)) | ||
return String.format("%." + decimals + "f", value).replace(",", "."); | ||
return valueOf(value); | ||
} | ||
|
||
/** Method to parse a numeric value and format without scientific notation | ||
* @param integers: number of digits before comma | ||
* @param decimals: number of digits after comma | ||
* @param value: value to fetch without scientific notation | ||
* @return value as {@link String} (es.) 9.2221111228E-6 -> 0.0000092221111228 | ||
* **/ | ||
public static String sNotationParse(int integers, int decimals, Number value){ | ||
if(integers < 0) | ||
throw new IllegalArgumentException("Integers digits value must be positive"); | ||
if(decimals < 0) | ||
throw new IllegalArgumentException("Decimals digits value must be positive"); | ||
if(value == null) | ||
throw new IllegalArgumentException("Value cannot be null"); | ||
if(!(value instanceof Integer)) | ||
return String.format("%"+ integers + "." + decimals + "f", value).replace(",", "."); | ||
return valueOf(value); | ||
} | ||
|
||
} |
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