PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 10, 2022

[FIXED] how to increment a decimal/float value by 0.1 or 0.001 according to degree of decimal value in java

 August 10, 2022     bigdecimal, decimal, floating-point, java, string     No comments   

Issue

I have a decimal number eg 65.435 or 9.2 or 10.23 , now i have to increment it as 65.436, 9.3,10.24.

Is there any utility method present for that in java?

I know we can do it by checking decimal place and then increment, but i want like in case of integer if we use '++' it increment the value.

Can anyone suggest a better way to handle.


Solution

spelling out Mr.Robot's comment:

BigDecimal bd = new BigDecimal("1.234");
bd = new BigDecimal(bd.unscaledValue().add(BigInteger.ONE), bd.scale());


Answered By - Reto Höhener
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing