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

  • Home
  • SEARCH
  • 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 7868063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:52:58+00:00 2026-06-03T00:52:58+00:00

How to fix the value of a variable to two digits after the decimal

  • 0

How to fix the value of a variable to two digits after the decimal point if the value coming from the database is of money data type.
Also in database no precision and scale is defined for money datatype.

Ex. value from database is: 3.7700(of money datatype)

output needed: 3.77

By output i mean saving the value in a variable and printing it. Also i converted it to double and than parse it to two decimal points. But my doubt is do we have any other method which directly work on money datatype without typecasting?

  • 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-03T00:53:00+00:00Added an answer on June 3, 2026 at 12:53 am

    If the database has no precision of its own , you can use your own specifier , e.g. use System.out.println("%.2f",<money variable>); . where %.2f is used to limit the limit to 2 places after the . and f is the specifier for floating data type

    From [this site][1]

    [1]: http://www.drdobbs.com/jvm/184405653 i quote the following paragraph :

    `The toDouble() method converts a monetary value to a double floating-point value.
    However, you should avoid using the converted value for computational purposes, owing
    to the problems associated with the use of floating-point data types with 
    monetary data.
    
    You can also convert a monetary value to a long integer data type (having an implied
    scaling factor of 2). In this case, an automatic round-off to the nearest whole cent is
    performed.`
    

    So convert your money variable to any type with sufficient range and you can use the converted value and cast the decimals to 2 or any number of places you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on transferring data from one database to another. For this I have
I want to format a numeric value to two decimal points (it is an
Any ideas how I can fix this? Line 58, Column 72: Bad value fancybox2
I want to fix the width of bar and whenever bar data changes dynamically
I've been trying for several days to: set the value of the variable w
i have two sub activities apart from main activity. The sequence of calls go
my data set has two variables ID and diagnosis . I am trying to
Hi I need to check the value of two variables if they are null
Flash receives the XML, but the values are wrong. How do I fix this?
I need to fix some text that lies between delimiters for the following cases:

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.