Skip to content

Add more Base Units - #452

Closed
fabgio wants to merge 1 commit into
unitsofmeasurement:masterfrom
fabgio:more-base-units
Closed

Add more Base Units#452
fabgio wants to merge 1 commit into
unitsofmeasurement:masterfrom
fabgio:more-base-units

Conversation

@fabgio

@fabgio fabgio commented Aug 18, 2026

Copy link
Copy Markdown

Add new Base Units: Millimetre (Symbol:mm), Centimetre(Symbol:cm) and Kilometre (Symbol:km)
Close issue: #451


This change is Reviewable

@andi-huber

Copy link
Copy Markdown
Member

As far as I know, there are exactly 7 base units in SI. Those form a fixed set of building blocks from which other units are derived.

For Example

Kilogram

public static final Unit<Mass> KILOGRAM = addUnit(new BaseUnit<Mass>("kg", "Kilogram", UnitDimension.MASS), Mass.class);

is the SI base unit for Mass and e.g. Gram is derived from it the following way:

/**
 * The SI derived unit for mass quantities (standard name <code>g</code>). The
 * base unit for mass quantity is {@link #KILOGRAM}.
 */
public static final Unit<Mass> GRAM = addUnit(INSTANCE.units, KILOGRAM.divide(1000), "Gram");

If you derive Millimetre, Centimetre and Kilometre adequately from the base unit Metre that would make your code correct.

That said, adding some so called prefixed units and not others to the Units class might be opinionated. But I have no strong opinion against adding those 3.

@fabgio

fabgio commented Aug 18, 2026

Copy link
Copy Markdown
Author

As as I know the divide method provides overloaded signatures for performing division but I do not need any of that. If you don't mind I need the mentioned Base Units.

@fabgio

fabgio commented Aug 20, 2026

Copy link
Copy Markdown
Author

I think I solved the issue as:
public static final Unit<Length> MILLIMETRE = MetricPrefix.MILLI(METRE); SimpleUnitFormat.getInstance().label(MILLIMETRE, "mm");

@fabgio fabgio closed this Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants