Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting MeasureBag to Amount of Unit #24

Open
seandenigris opened this issue Dec 9, 2020 · 1 comment
Open

Converting MeasureBag to Amount of Unit #24

seandenigris opened this issue Dec 9, 2020 · 1 comment

Comments

@seandenigris
Copy link

seandenigris commented Dec 9, 2020

I tried the following and got aMeasureBag back, but I expected 10.21

amount := 10.21.
dollarAmt := amount // 1.
centsAmt := (amount \\ 1 * 100) asInteger.
total := (AmDollar new * dollarAmt) +
(centsAmt * AmCent new).
total / (1 * AmDollar new).

Also I tried convertTo: but got a subclassResponsibility error...

where:

AmDollar class>>#new
	^ super new
		initializeBaseUnit: AmCent new
		conversionFactor: 100
		nameForOne: 'dollar'
		nameForMany: 'dollars'
		sign: 'USD'

and

AmCent class>>#new
	^ super new
		initializeNameFomOne: 'cent'
		nameForMany: 'cents'
		sign: 'c USD'
@gcotelli
Copy link
Member

Are AnDollar and AnCent available somewhere to look at them?
Are AmDollar new creating a new unit each time or it's the same? If there are different instances probably the conversions will not simplify them because it will consider them as different units... I find a bit strange that you want a new class for every currency...

Maybe a model where you have a more generic class for cents and for currencies makes more sense.. and dollar/cents of dollars will be just instances.. Obviously you will need a place to have these well known instances so will allways get the same one for the dollar

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

No branches or pull requests

2 participants