How to convert terabytes to petabytes in Java

1 Answer

0 votes
public class Main {
    static double terabytesToPetabytes(long terabytes) {
        return terabytes / 1024.0;
    }

    public static void main(String[] args) {
        int tb1 = 1398;
        int tb2 = 10;

        System.out.printf("%.2fPB%n", terabytesToPetabytes(tb1));
        System.out.printf("%.4fPB%n", terabytesToPetabytes(tb2));
    }
}



/*
run:
   
1.37PB
0.0098PB
   
*/

 



answered Nov 24, 2024 by avibootz

Related questions

1 answer 185 views
1 answer 183 views
1 answer 257 views
257 views asked Sep 14, 2020 by avibootz
1 answer 257 views
...