cancel
Showing results for 
Search instead for 
Did you mean: 

big decimal value truncate

Former Member
0 Kudos

Hi,

I have a big decimal field (789.8098908908908). I want to take only 789.809. Could you please tell how can I do that?.

I appreciate your help on this.

Thanks,

Sunita.

Accepted Solutions (0)

Answers (2)

Answers (2)

sridhar_k2
Active Contributor
0 Kudos

Hi Sunita,

You can use this simple code to truncate the big decimal value.

BigDecimal bb = new BigDecimal("12.32255")

DecimalFormat df = new DecimalFormat("#.##");

manager.reportSuccess(df.format(d));

// Gives out put as 12.32

Regards,

Sridhar

Former Member
0 Kudos

Thanks sridhar and Valery.

Former Member
0 Kudos

sunita,

Use this as example:


final BigDecimal value1 = new BigDecimal("789.8098908908908");
System.out.println(value1);
final BigDecimal value2 = value1.setScale(3, BigDecimal.ROUND_DOWN);
System.out.println(value2);

Btw, you have asked almost the same question in another thread:

It is better to continue discussion in one thread and ask additional questions there rather then spawn additional threads.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net