formatter - How to add decimal point before x digits in Java -


lets suppose have value 12345678 , number x=2, , want final output 123456.78 , if value of x 4, final output 1234.5678.

please tell how can achieve this?

given you're dealing shifting decimal point, i'd use bigdecimal:

long integral = 12345678l; int x = 4; // or 2, or whatever bigdecimal unscaled = new bigdecimal(integral); bigdecimal scaled = unscaled.scalebypoweroften(-x); system.out.println(scaled); // 1234.5678 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -