Skip to content

Commit

Permalink
Remap coins.json for CryptocurrencyTool
Browse files Browse the repository at this point in the history
Add ScientificNotationParser tool
  • Loading branch information
N7ghtm4r3 committed Jul 12, 2022
1 parent 4bdf2d2 commit d0fb6a9
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 45 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public <T> T getJSONErrorResponse() {
/** Method to get JSON object of response of request, already red, without read again {@link HttpURLConnection}'s stream
* @param response: success response or errorResponse
* @return response of request formatted as {@link JSONObject} or {@link JSONArray} object
* @throws JSONException if is not a JSON format response and return response as {@link String}
* @throws JSONException if is not a JSON sNotationParse response and return response as {@link String}
* **/
private <T> T getJSONResponseObject(String response){
try {
Expand Down

This file was deleted.

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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public String textualizeAssetPercent(double startValue, double lastValue, int de
return textualizeAssetPercent(computeAssetPercent(startValue, lastValue, decimalDigits));
}

/** Method to format percent between two values and textualize it
* @param percent: value to format
/** Method to sNotationParse percent between two values and textualize it
* @param percent: value to sNotationParse
* @return percent value formatted es. +8% or -8% as {@link String}
* **/
public String textualizeAssetPercent(double percent){
Expand All @@ -71,8 +71,8 @@ else if(percent < 0)
return "=" + percent + "%";
}

/** Method to format percent between two values and textualize it
* @param percent: value to format
/** Method to sNotationParse percent between two values and textualize it
* @param percent: value to sNotationParse
* @param decimalDigits: number of digits to round final value
* @return percent value formatted es. +8% or -8% as {@link String}
* **/
Expand Down

0 comments on commit d0fb6a9

Please sign in to comment.