scaled decimal number for currency

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

scaled decimal number for currency

pdigonzelli1
Hi, I want to use scaled decimal numbers for currency amounts. I am using Glorp too.
The problem is that when Glorp generates sql sentences has a problem with #printOn: of ScaledDecimal wich produces output that include the scale value.
I do not want to modify printOn: on ScaledDecimal. Any suggestion for this problem?

TIA





Ing. Pablo Digonzelli
Software Solutions
IP-Solutiones SRL
Metrotec SRL
25 de Mayo 521
San Miguel de Tucumán
Email: [hidden email]
[hidden email]
Cel: 5493815982714

Reply | Threaded
Open this post in threaded view
|

Re: scaled decimal number for currency

stepharo
can you give example?


Le 5/3/15 13:21, Pablo R. Digonzelli a écrit :
Hi, I want to use scaled decimal numbers for currency amounts. I am using Glorp too.
The problem is that when Glorp generates sql sentences has a problem with #printOn: of ScaledDecimal wich produces output that include the scale value.
I do not want to modify printOn: on ScaledDecimal. Any suggestion for this problem?

TIA





Ing. Pablo Digonzelli
Software Solutions
IP-Solutiones SRL
Metrotec SRL
25 de Mayo 521
San Miguel de Tucumán
Email: [hidden email]
[hidden email]
Cel: 5493815982714


Reply | Threaded
Open this post in threaded view
|

Re: scaled decimal number for currency

wernerk
In reply to this post by pdigonzelli1
do you perhaps mean this?
b:=ScaledDecimal newFromNumber: 5.8777 scale: 2." 5.88s2"
b printShowingDecimalPlaces:2." '5.88'"
on a stream you can use 'printOn: aStream showingDecimalPlaces:
placesDesired'
werner

On 03/05/2015 01:21 PM, Pablo R. Digonzelli wrote:

> Hi, I want to use scaled decimal numbers for currency amounts. I am
> using Glorp too.
> The problem is that when Glorp generates sql sentences has a problem
> with #printOn: of ScaledDecimal wich produces output that include the
> scale value.
> I do not want to modify printOn: on ScaledDecimal. Any suggestion for
> this problem?
>
> TIA
>
>
>
>
> ****
> ------------------------------------------------------------------------
> *Ing. Pablo Digonzelli*
> Software Solutions
> IP-Solutiones SRL
> Metrotec SRL
> 25 de Mayo 521
> San Miguel de Tucumán
> Email: [hidden email]
> [hidden email]
> Cel: 5493815982714
>

Reply | Threaded
Open this post in threaded view
|

Re: scaled decimal number for currency

pdigonzelli1
In reply to this post by stepharo
I'll try.
Supose i have an item wich has an id and a  price .
For example id is 77 and price 41.69.
If I use ScaledDecimal with scale 2 for price , glorp create this string for query execution: 'INSERT INTO item (id,price)  VALUES (77,41.69s2); 
and of course give me a GlorpDatabaseWriteError for the 's2' part of the string.
If i comment the line   "aStream nextPut: $s; print: scale." in printOn: of ScaledDecimal glorp works with no problem.

I hope you understand. Sorry for my bad english

TIA




Ing. Pablo Digonzelli
Software Solutions
IP-Solutiones SRL
Metrotec SRL
25 de Mayo 521
San Miguel de Tucumán
Email: [hidden email]
[hidden email]
Cel: 5493815982714


De: "stepharo" <[hidden email]>
Para: "Any question about pharo is welcome" <[hidden email]>
Enviados: Jueves, 5 de Marzo 2015 10:04:06
Asunto: Re: [Pharo-users] scaled decimal number for currency

can you give example?


Le 5/3/15 13:21, Pablo R. Digonzelli a écrit :
Hi, I want to use scaled decimal numbers for currency amounts. I am using Glorp too.
The problem is that when Glorp generates sql sentences has a problem with #printOn: of ScaledDecimal wich produces output that include the scale value.
I do not want to modify printOn: on ScaledDecimal. Any suggestion for this problem?

TIA





Ing. Pablo Digonzelli
Software Solutions
IP-Solutiones SRL
Metrotec SRL
25 de Mayo 521
San Miguel de Tucumán
Email: [hidden email]
[hidden email]
Cel: 5493815982714



Reply | Threaded
Open this post in threaded view
|

Re: scaled decimal number for currency

pdigonzelli1
In reply to this post by wernerk

I know that. the problem is that glorp generates the string in question , not me.


Ing. Pablo Digonzelli
Software Solutions
IP-Solutiones SRL
Metrotec SRL
25 de Mayo 521
San Miguel de Tucumán
Email: [hidden email]
[hidden email]
Cel: 5493815982714

----- Mensaje original -----
De: "Werner Kassens" <[hidden email]>
Para: "Any question about pharo is welcome" <[hidden email]>
Enviados: Jueves, 5 de Marzo 2015 11:04:01
Asunto: Re: [Pharo-users] scaled decimal number for currency

do you perhaps mean this?
b:=ScaledDecimal newFromNumber: 5.8777 scale: 2." 5.88s2"
b printShowingDecimalPlaces:2." '5.88'"
on a stream you can use 'printOn: aStream showingDecimalPlaces:
placesDesired'
werner

On 03/05/2015 01:21 PM, Pablo R. Digonzelli wrote:

> Hi, I want to use scaled decimal numbers for currency amounts. I am
> using Glorp too.
> The problem is that when Glorp generates sql sentences has a problem
> with #printOn: of ScaledDecimal wich produces output that include the
> scale value.
> I do not want to modify printOn: on ScaledDecimal. Any suggestion for
> this problem?
>
> TIA
>
>
>
>
> ****
> ------------------------------------------------------------------------
> *Ing. Pablo Digonzelli*
> Software Solutions
> IP-Solutiones SRL
> Metrotec SRL
> 25 de Mayo 521
> San Miguel de Tucumán
> Email: [hidden email]
> [hidden email]
> Cel: 5493815982714
>

Reply | Threaded
Open this post in threaded view
|

Re: scaled decimal number for currency

Esteban A. Maringolo
Can you please share with us how are you defining the mapping for such field?


For what I was able to see in the current implementation the Pharo
dialect doesn't provide support for ScaledDecimals.
PharoDialect doesn't provide a #fixedPointType, so the number is
coerced to a float.


Adding support for it shouldn't be much hassle. Let me see if I can
spare a couple of hours to look into this.

See comment of #convertToNumber:for:
"Convert to an arbitrary numeric type. Make sure our precision
matches. *Hate* floating point"

:)



Esteban A. Maringolo


2015-03-05 11:16 GMT-03:00 Pablo R. Digonzelli <[hidden email]>:

>
> I know that. the problem is that glorp generates the string in question , not me.
>
>
> Ing. Pablo Digonzelli
> Software Solutions
> IP-Solutiones SRL
> Metrotec SRL
> 25 de Mayo 521
> San Miguel de Tucumán
> Email: [hidden email]
> [hidden email]
> Cel: 5493815982714
>
> ----- Mensaje original -----
> De: "Werner Kassens" <[hidden email]>
> Para: "Any question about pharo is welcome" <[hidden email]>
> Enviados: Jueves, 5 de Marzo 2015 11:04:01
> Asunto: Re: [Pharo-users] scaled decimal number for currency
>
> do you perhaps mean this?
> b:=ScaledDecimal newFromNumber: 5.8777 scale: 2." 5.88s2"
> b printShowingDecimalPlaces:2." '5.88'"
> on a stream you can use 'printOn: aStream showingDecimalPlaces:
> placesDesired'
> werner
>
> On 03/05/2015 01:21 PM, Pablo R. Digonzelli wrote:
>> Hi, I want to use scaled decimal numbers for currency amounts. I am
>> using Glorp too.
>> The problem is that when Glorp generates sql sentences has a problem
>> with #printOn: of ScaledDecimal wich produces output that include the
>> scale value.
>> I do not want to modify printOn: on ScaledDecimal. Any suggestion for
>> this problem?
>>
>> TIA
>>
>>
>>
>>
>> ****
>> ------------------------------------------------------------------------
>> *Ing. Pablo Digonzelli*
>> Software Solutions
>> IP-Solutiones SRL
>> Metrotec SRL
>> 25 de Mayo 521
>> San Miguel de Tucumán
>> Email: [hidden email]
>> [hidden email]
>> Cel: 5493815982714
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: scaled decimal number for currency

Sven Van Caekenberghe-2
I would store whole cents in the database.

EUR 10.99 would be stored as 1099 eurocent.

But yes, the mapping is what is missing and what you should look at.

> On 05 Mar 2015, at 15:40, Esteban A. Maringolo <[hidden email]> wrote:
>
> Can you please share with us how are you defining the mapping for such field?
>
>
> For what I was able to see in the current implementation the Pharo
> dialect doesn't provide support for ScaledDecimals.
> PharoDialect doesn't provide a #fixedPointType, so the number is
> coerced to a float.
>
>
> Adding support for it shouldn't be much hassle. Let me see if I can
> spare a couple of hours to look into this.
>
> See comment of #convertToNumber:for:
> "Convert to an arbitrary numeric type. Make sure our precision
> matches. *Hate* floating point"
>
> :)
>
>
>
> Esteban A. Maringolo
>
>
> 2015-03-05 11:16 GMT-03:00 Pablo R. Digonzelli <[hidden email]>:
>>
>> I know that. the problem is that glorp generates the string in question , not me.
>>
>>
>> Ing. Pablo Digonzelli
>> Software Solutions
>> IP-Solutiones SRL
>> Metrotec SRL
>> 25 de Mayo 521
>> San Miguel de Tucumán
>> Email: [hidden email]
>> [hidden email]
>> Cel: 5493815982714
>>
>> ----- Mensaje original -----
>> De: "Werner Kassens" <[hidden email]>
>> Para: "Any question about pharo is welcome" <[hidden email]>
>> Enviados: Jueves, 5 de Marzo 2015 11:04:01
>> Asunto: Re: [Pharo-users] scaled decimal number for currency
>>
>> do you perhaps mean this?
>> b:=ScaledDecimal newFromNumber: 5.8777 scale: 2." 5.88s2"
>> b printShowingDecimalPlaces:2." '5.88'"
>> on a stream you can use 'printOn: aStream showingDecimalPlaces:
>> placesDesired'
>> werner
>>
>> On 03/05/2015 01:21 PM, Pablo R. Digonzelli wrote:
>>> Hi, I want to use scaled decimal numbers for currency amounts. I am
>>> using Glorp too.
>>> The problem is that when Glorp generates sql sentences has a problem
>>> with #printOn: of ScaledDecimal wich produces output that include the
>>> scale value.
>>> I do not want to modify printOn: on ScaledDecimal. Any suggestion for
>>> this problem?
>>>
>>> TIA
>>>
>>>
>>>
>>>
>>> ****
>>> ------------------------------------------------------------------------
>>> *Ing. Pablo Digonzelli*
>>> Software Solutions
>>> IP-Solutiones SRL
>>> Metrotec SRL
>>> 25 de Mayo 521
>>> San Miguel de Tucumán
>>> Email: [hidden email]
>>> [hidden email]
>>> Cel: 5493815982714
>>>
>>
>