0

I have a string like: String value = "0.0232300"; and I want to remove those two 0 from the decimal part (the 0 which are after number 3) without parsing the String to Double. Is the any way to do this using String methos or regex?

John R.
  • 400
  • 4
  • 11
  • 1
    `value.replaceAll("0+$", "")`. – Andy Turner Mar 27 '20 at 11:26
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Mar 27 '20 at 11:27
  • 1
    @AndyTurner Try it with `20000`. – Wiktor Stribiżew Mar 27 '20 at 11:27
  • @WiktorStribiżew sure. Depends on exactly what OP means by "I have a string like..." as to whether you need to care about that. – Andy Turner Mar 27 '20 at 11:29
  • @AndyTurner all is clear: *remove those two 0 **from the decimal part*** – Wiktor Stribiżew Mar 27 '20 at 11:31
  • @AndyTurner thank you very much for your answer. It works for 0.2200 but it does not work for 2200. – John R. Mar 27 '20 at 11:34

0 Answers0