Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:51:07+00:00 2026-06-11T23:51:07+00:00

I have a string array in an object which is storing a decimal value.

  • 0

I have a string array in an object which is storing a decimal value.

String [] array = "12345.123456789";

I want it to be formatted as 12345.1234

I tried it with the following but resulted in a Number Format Exception.

BigDecimal value = new BigDecimal(array.toString()).setScale( 4, BigDecimal.ROUND_HALF_UP );
array = ( Object )value.toString();

I am new to java so can anyone please help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:51:08+00:00Added an answer on June 11, 2026 at 11:51 pm

    String [] array = "12345.123456789"; is not a valid statement – either it is a String or an array, so you need to choose between the following two statements:

    String s = "12345.123456789"; //a string
    String[] array = {"12345.123456789"}; //an array
    

    If you use the first form, you can round it with:

    BigDecimal rounded = new BigDecimal(s).setScale( 4, BigDecimal.ROUND_HALF_UP );
    String roundedStr = rounded.toString();
    

    If you use the second form, you can use this:

    BigDecimal rounded = new BigDecimal(array[0]).setScale( 4, BigDecimal.ROUND_HALF_UP );
    String roundedStr = rounded.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string array(8) { [2]=> object(stdClass)#871 (2) { ["access"]=> int(0) ["value"]=> string(4)
I have a string array selectCancel with setter and getter methods, which is a
I have a string array which holds the name of 500 stocks. Now i
I've got an object[] array which contains some mixture of builtin types, like Int/Byte/String,
I have an array of type object which are strings. I would like to
I have a string array which holds the names of the weekdays: private final
I have a problem in copying the data in array from object variable which
I have a List of objects which contain a string array as one of
I am trying to access a String array which i have created in my
i have an array of Tag objects class Tag { public string Name; public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.