on 01-28-2022 8:13 AM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.