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 6988855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:08:08+00:00 2026-05-27T19:08:08+00:00

I need to make a lot of operations using BigDecimal, and I found having

  • 0

I need to make a lot of operations using BigDecimal, and I found having to express

Double a = b - c * d; //natural way

as

BigDecimal a = b.subtract(c.multiply(d))//BigDecimal way

is not only ugly, but a source of mistakes and communication problems between me and business analysts. They were perfectly able to read code with Doubles, but now they can’t.

Of course a perfect solution will be java support for operator overloading, but since this not going to happen, I’m looking for an eclipse plugin or even an external tool that make an automatic conversion from “natural way” to “bigdecimal way”.

I’m not trying to preprocess source code or dynamic translation or any complex thing, I just want something I can input text and get text, and keep the “natural way” as a comment in source code.

P.S.: I’ve found this incredible smart hack but I don’t want to start doing bytecode manipulation. Maybe I can use that to create a Natural2BigDecimal translator, but I don’t want to reinvent the wheel if someone has already done such a tool.

I don’t want to switch to Scala/Groovy/JavaScript and I also can’t, company rules forbid anything but java in server side code.

  • 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-05-27T19:08:08+00:00Added an answer on May 27, 2026 at 7:08 pm

    “I’m not trying to preprocess source code … I just want something I can input [bigDecimal arithmetic expression] text”.

    Half of solving a problem is recognizing the problem for what it is. You exactly want something to preprocess your BigDecimal expressions to produce legal Java.

    You have only two basic choices:

    • A stand-alone “domain specific language” and DSL compiler that accepts “standard” expressions and converts them directly to Java code. (This is one kind of preprocessor). This leaves you with the problem of keeping all the expression fragments around, and somehow knowing where to put them in the Java code.

    • A tool that reads the Java source text, finds such expressions, and converts them to BigDecimal in the text. I’d suggest something that let you code the expressions outside the actual code and inserted the translation.

    Perhaps (stolen from another answer):

     // BigDecimal a = b - c * d;
     BigDecimal a = b.subtract( c.multiply( d ) );
    

    with the meaning “compile the big decimal expression in the comment into its java equivalent, and replace the following statement with that translation.

    To implement the second idea, you need a program transformation system, which can apply source-to-source rewriting rules to transforms (generate as a special case of transform) the code. This is just a preprocessor that is organized to be customizable to your needs.

    Our DMS Software Reengineering Toolkit with its Java Front End could do this. You need a full Java parser to do that transformation part; you’ll want name and type resolution so that you can parse/check the proposed expression for sanity.

    While I agree that the as-is Java notation is ugly, and your proposal would make it prettier, my personal opinion is this isn’t worth the effort. You end up with a dependency on a complex tool (yes, DMS is complex: manipulating code isn’t easy) for a rather marginal gain.

    If you and your team wrote thousands of these formulas, or the writers of such formulas were Java-naive it might make sense. In that case,
    I’d go further, and simply insist you write the standard expression format where you need it. You could customize the Java Front End to detect when the operand types were of decimal type, and do the rewriting for you. Then you simply run this preprocessor before every Java compilation step.

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

Sidebar

Related Questions

I'm using variant a lot in my code and I need to make comparisons
I need to make a collection with a lot of movies, but I was
I need to make some recurrent modification in a lot of files (C++). I
I am have a lot of code that I need to optimize and make
I need make some action (dump statistical data) before the Dart program ends. The
I need make all of my posts update. I use bulk upload for store,
Need to make certain Ruby strings in my program to be immutable. What is
I need to make a administrative GUI with lots of functionality like lists, forms,
I need to make a moderate system like the one in fmylife.com. Basically the
I need to make a point in time branch, when we release a new

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.