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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:11:29+00:00 2026-05-15T07:11:29+00:00

I need to represent the unit of Percent per second using the JScience.org’s JSR

  • 0

I need to represent the unit of Percent per second using the JScience.org’s JSR 275 units and measures implementation. I am trying to do to the following:

Unit<Dimensionless> PERCENT_PER_SECOND = NonSI.PERCENT.divide(Si.SECOND).asType(Dimensionless.class)

but I am getting a ClassCastException when I try to do that.

The following works, but I’m not sure if there’s a better way:

public interface PercentOverTime extends Quantity {}
public static Unit<PercentOverTime> PERCENT_PER_SECOND = new BaseUnit<PercentOverTime>("%/s");

Any thoughts? The closest I could find to this is the question on Cooking Measurements (which is how I saw how to define your own units).

  • 1 1 Answer
  • 1 View
  • 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-15T07:11:29+00:00Added an answer on May 15, 2026 at 7:11 am

    I wrote up this code sample to test out the math here:

    public void testUnit() {
        // define two points on a function from t -> %
        // the rate of change between these two points
        // should have unit %/t
        Measure<Double, Dimensionless> p0 = Measure.valueOf(50.0, NonSI.PERCENT);
        Measure<Double, Dimensionless> p1 = Measure.valueOf(20.0, NonSI.PERCENT);
    
        Measure<Double, Duration> timeDifference = Measure.valueOf(10.0, SI.SECOND);
    
        // JSR-275 has no Amount, so have to convert and do math ourselves
        // these doubles are percents
        double p0Raw = p0.doubleValue(NonSI.PERCENT);
        double p1Raw = p1.doubleValue(NonSI.PERCENT);
    
        // this duration is in seconds
        double timeDifferenceRaw = timeDifference.doubleValue(SI.SECOND);
    
        // this is the slope of the secant between the two points
        // so it should be the %/s we want
        double rateSecant = (p1Raw - p0Raw) / timeDifferenceRaw;
    
        // let's see what we get
        Measure<Double, ?> answer = Measure.valueOf(rateSecant,
                                                    NonSI.PERCENT.divide(SI.SECOND));
        System.out.println(answer);
    }
    

    If your original function has time as the independent variable (e.g. as seconds) and a ratio as the independent variable (e.g. as a percent), then the derivative of this function with regard to time will still have time as the independent variable, but will have ‘ratio per time’ as the dependent.

    Yes, ratios are dimensionless, so this is a little bit odd, but you could imagine a graph of the percent change day over day in a stock price and then a graph of the change in the percent change in a stock price day over day day over day.

    So what does this print out?

    -3.0 %/s
    

    Which is what we expect the rate of change to be for a change from 50 to 20 percent over 10 seconds.

    So your unit construction should look like:

        Unit<?> magicUnit = NonSI.PERCENT.divide(SI.SECOND);
        Dimension magicDimension = Dimension.NONE.divide(Dimension.TIME);
    
        System.out.println(magicUnit + " measures " + magicDimension + " ("
                + magicUnit.getDimension() + ")");
    

    Indeed this prints %/s measures 1/[T] (1/[T]), as we expect.

    So we have a Unit and Dimension and can make Measures. What is the Quantity we are measuring? The docs say this about Quantity:

    Distinct quantities have usually
    different physical dimensions;
    although it is not required nor
    necessary, for example Torque and
    Energy have same dimension but are of
    different nature (vector for torque,
    scalar for energy).

    So while Frequency would seem to be the correct Quantity, it doesn’t really express the semantic quantity we seem to be discussing.

    In closing, your first line of code doesn’t work because in the included model 1/[T] measures the quantity Freqency, not the quantity Dimensionless. So if you don’t want to make your own Quantity, use Unit. The Dimension you are looking for is None/Time, or %/second if you want the correct scalar multipliers in there. Finally, it’s up to you whether you want to make your own Quantity, but it might be worthwhile if you’re using this in a lot of places.

    It would also be worthwhile to check out the latest developments in the JScience space since it seems like they decided Amount (with add, subtract, multiply, divide, pow, etc. methods) was needed. It would be really easy to do all this dimensional analysis with Amount. Just do a Percent Amount minus a Percent Amount and divide by a Seconds amount and it should do the units for you.

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

Sidebar

Related Questions

I need to represent inheritance like Person/Student. How do you do that in LInqToSql?
I need a way to represent a 2-D array (a dense matrix) of doubles
I need to lock the browser scrollbars when I show a div that represent
i have very simple problem. I need to create model, that represent element of
I need to represent single precision numbers as text in a way that won't
I have a next problem. I need to represent a pressed keys combination in
I have a flattened table that contains columns that represent groups that need to
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.
Need to an expression that returns only things with an I followed by either

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.