Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

converting amount into millions nad billions Java

public String truncateNumber(float floatNumber) {
    long million = 1000000L;
    long billion = 1000000000L;
    long trillion = 1000000000000L;
    long number = Math.round(floatNumber);
    if ((number >= million) && (number < billion)) {
        float fraction = calculateFraction(number, million);
        return Float.toString(fraction) + "M";
    } else if ((number >= billion) && (number < trillion)) {
        float fraction = calculateFraction(number, billion);
        return Float.toString(fraction) + "B";
    }
    return Long.toString(number);
}

public float calculateFraction(long number, long divisor) {
    long truncate = (number * 10L + (divisor / 2L)) / divisor;
    float fraction = (float) truncate * 0.10F;
    return fraction;
}
Comment

PREVIOUS NEXT
Code Example
Java :: Java Documenting assumptions 
Java :: Returning methods 
Java :: constraints in Grails 
Java :: make form items vertica 
Java :: join table in where clause criteria in java hibernate 
Java :: GLG203 
Java :: java instanciar objeto File 
Java :: .class to .java 
Java :: using handler runnable for refresh android 
Java :: Java socket connect to gmail 
Java :: what does the continue keyword do in java 
Java :: MojoExecutionException when generate sources cxf-xjc-plugin:3.3.0 java11 
Java :: what is assignment in java with example 
Java :: Java array nested equals 
Java :: does java recognize on a txt file 
Java :: ava program to add two numbers taking input from user 
Java :: Custom Layout to listview 
Java :: convertir un float en int en java 
Java :: java arduino 
Java :: how to search element in jtablejava 
Java :: multipleQuastion.Java 
Java :: jsonpath xpath java 
Java :: nikita kaksharov 
Java :: java trim unicode u200b 
Java :: Which package contains the Math classin java? 
Java :: strings in java are represented as 
Java :: ant bild skip java doc 
Java :: java non blocking notifier 
Java :: minecraft java plugin shift 
Java :: bytecode into source code 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =