cancel
Showing results for 
Search instead for 
Did you mean: 

How to Pad zeros including decimal values

former_member485301
Participant
0 Kudos

Hi,

I have an requirement to pad 7 zeros including decimal values.

eg:

1.25 -> 0001.25

2.00 -> 0000002

170.00 -> 0000170

if zero's after decimal, then it can be ignored, if values after decimal then it should be padded in 7 characters including decimal value.

Please guide.

Thanks,

Vinoth

Accepted Solutions (0)

Answers (2)

Answers (2)

juan_vasquez2
Active Participant
0 Kudos

Hi vinothg01

Just use arithmetic function FormatNumber

Regards

asutoshmaharana2326
Active Participant
0 Kudos

Dear Vinoth,

Please try to implement below logic in UDF for appropriate results.

Thanks,

Asutosh

import java.text.DecimalFormat;
class NumberPad {
    public static void main(String[] args) {
        double yournumber = 100.25;
        DecimalFormat df = new DecimalFormat("0000000.##");
        String newin = df.format(yournumber);
        try{
        int integerPlaces = newin.indexOf('.');
        int decimalPlaces = newin.length() - integerPlaces - 1;
        newin = newin.substring(decimalPlaces+1);
        }catch(StringIndexOutOfBoundsException e){
        }
        System.out.println(newin);
    }
}
asutoshmaharana2326
Active Participant
0 Kudos

Tes1 with input as 1.25

Test2 with input as 1.00