[web2py] Re: Decimal fields error as float

2015-09-13 Thread Massimo Di Pierro
Solution 1) from decimal import Decimal t.fee = Decimal('0.3') result = t.bal - t.fee # result is in Decimal or t.fee =0.3 result = float(t.bal) - t.fee # result is in float On Wednesday, 9 September 2015 23:25:48 UTC-5, Dmitri Ermolaev wrote: > > in db: > >Field('bal', 'decimal(16,8)', de

[web2py] Re: Decimal( error )

2015-01-22 Thread Massimo Di Pierro
0E-8.00 is a float, not a decimal. Anyway, it is not a valid decimal either, it is 0. On Monday, 19 January 2015 23:22:10 UTC-6, Dmitry Ermolaev wrote: > > Yes, I use: > Field('balance', 'decimal(17,8)', readable=False, default = > Decimal('0.0')), > > Try use that field in table then a

[web2py] Re: Decimal( error )

2015-01-19 Thread Dmitry Ermolaev
Yes, I use: Field('balance', 'decimal(17,8)', readable=False, default = Decimal('0.0')), четверг, 24 июля 2014 г., 14:36:21 UTC+3 пользователь Massimo Di Pierro написал: > > This 'Decimal(16.8' is not a valid field type. Did you mean > 'decimal(16,8)' ? > > On Thursday, 24 July 2014 0

[web2py] Re: Decimal( error )

2014-07-24 Thread Massimo Di Pierro
This 'Decimal(16.8' is not a valid field type. Did you mean 'decimal(16,8)' ? On Thursday, 24 July 2014 06:02:41 UTC-5, Dmitry Ermolaev wrote: > > in db: > ... > Field(ddd, 'Decimal(16.8')), > ... > > than in admin db update > http://127.0.0.1:8000/polza/appadmin/update/db/goods/9 > > I see: >

[web2py] Re: Decimal fields showing as class=string in form

2011-12-14 Thread Anthony
Just submitted a patch. On Wednesday, December 14, 2011 9:38:48 PM UTC-5, Anthony wrote: > > I'd say it's a bug. For one thing, the input class is used for some client > side validation of numeric fields. > > Anthony > > On Wednesday, December 14, 2011 8:12:17 PM UTC-5, pbreit wrote: >> >> Does t

[web2py] Re: Decimal fields showing as class=string in form

2011-12-14 Thread Anthony
I'd say it's a bug. For one thing, the input class is used for some client side validation of numeric fields. Anthony On Wednesday, December 14, 2011 8:12:17 PM UTC-5, pbreit wrote: > > Does that mean it's a bug or should decimals be classed as strings? It > used to class the input field as "de

[web2py] Re: Decimal fields showing as class=string in form

2011-12-14 Thread pbreit
Does that mean it's a bug or should decimals be classed as strings? It used to class the input field as "decimal" which would seem to make sense. But I guess I could fix it on my end (probably just a CSS edit). I am doing this: input.decimal, input.integer { width:60px }

[web2py] Re: Decimal fields showing as class=string in form

2011-12-14 Thread Anthony
In SQLFORM.__init__, it looks like it checks whether field.type is in SQLFORM.widgets, but SQLFORM.widgets includes a 'decimal' key, which wouldn't match 'decimal(17,2)'. So looks like it then defaults to the string widget. Previously, the string widget used field.type as the input class (using

[web2py] Re: Decimal vs float

2011-12-02 Thread Cliff
No need. The Python tutorial says mixing integers and decimals in arithmetic is OK. Note version 2.7.1 in the following. cjk@mid-tower:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from

[web2py] Re: Decimal vs float

2011-12-01 Thread pbreit
Great info, thanks. I hadn't thought of using Decimal type for integers that might be involved in calculations. Can I simulate an integer with something like "decimal(4,0)"? For quantity, I'd rather show "1" and not "1.0".

[web2py] Re: Decimal vs float

2011-12-01 Thread Cliff
I forgot to say the Python tutorial says to use Decimal for financial calcs to avoid rounding errors. On Nov 27, 8:33 pm, pbreit wrote: > I have some price fields specified as type 'decimal'. But am finding that I > have to cast to 'float' do do any math (or the other to decimal.Decimal I > guess

[web2py] Re: Decimal vs float

2011-12-01 Thread Cliff
>> if ((form.vars.drops * form.vars.price_change) / form.vars.start_price) < >> 0.20: >> TypeError: can't multiply sequence by non-int of type 'Decimal' I think form.vars.drops is a string. I usually do something like Decimal(form.vars.somedecimalfield or 0) For the benefit of Python newcomers r

[web2py] Re: Decimal vs float

2011-12-01 Thread Ross Peoples
Further examples: quantity = 20.5 unit_cost = Decimal('2.99') total_cost = Decimal(str(quantity)) * unit_cost Or using the the example you provided above: if ((form.vars.drops * form.vars.price_change) / form.vars.start_price) < 0.20 Assuming that form.vars.drops is a float, and form.vars.pri

[web2py] Re: Decimal vs float

2011-12-01 Thread Ross Peoples
> > Is 'decimal' the best field type for storing financial amounts that will > be involved in math calculations? > I've been doing a lot of research on the decimal vs float thing for a while, and every database admin I've ever talked to about it says the same thing: When it comes to financial

[web2py] Re: Decimal vs float

2011-12-01 Thread pbreit
A version gotcha. This is OK on 2.7 but errors on 2.6: >>> from decimal import * >>> Decimal(1.0) Decimal('1') >>> from decimal import * >>> Decimal(1.0) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/decimal.py", line 649, in __new__ "First convert the f

[web2py] Re: Decimal vs float

2011-12-01 Thread pbreit
Also. I think this is a Python thing, not Web2py. I'm at a loss for what data type I should use for currencies. I wasn't expecting to run into these type problems (I'm a relative newbie!). if form.vars.shipping_amount > (form.vars.start_price * Decimal(0.2)): File "/usr/lib/python2.6/decim

[web2py] Re: Decimal vs float

2011-12-01 Thread pbreit
Examples. shipping_amount and start_price both decimals. if form.vars.shipping_amount > (form.vars.start_price * 0.2): TypeError: unsupported operand type(s) for *: 'Decimal' and 'float' drops is integer, price_change, start_price are decimals. if ((form.vars.drops * form.vars.price_change)

[web2py] Re: Decimal vs float

2011-11-27 Thread Massimo Di Pierro
You should not need any casting to do math computations. Can you provide an example of what you do, perhaps something does not behave as intended. On Nov 27, 7:33 pm, pbreit wrote: > I have some price fields specified as type 'decimal'. But am finding that I > have to cast to 'float' do do any ma

[web2py] Re: decimal validator by default or not

2010-11-18 Thread mdipierro
If we were to do it I would have gone for (-99.99,+99.99) On Nov 18, 10:50 am, Richard Vézina wrote: > Ok... I could set it to : (0,00.99) for example. > > Thanks! > > Richard > > On Wed, Nov 17, 2010 at 6:00 PM, mdipierro wrote: > > 4,2 have to do with precision, not range. > > > On Nov 17, 4:

Re: [web2py] Re: decimal validator by default or not

2010-11-18 Thread Richard Vézina
Ok... I could set it to : (0,00.99) for example. Thanks! Richard On Wed, Nov 17, 2010 at 6:00 PM, mdipierro wrote: > 4,2 have to do with precision, not range. > > On Nov 17, 4:18 pm, Richard Vézina > wrote: > > Ok, > > > > I think I wrongly define the IS_DECIMAL_IN_RANGE > > > > I set it to (

[web2py] Re: decimal validator by default or not

2010-11-17 Thread mdipierro
4,2 have to do with precision, not range. On Nov 17, 4:18 pm, Richard Vézina wrote: > Ok, > > I think I wrongly define the IS_DECIMAL_IN_RANGE > > I set it to (0,99.99) > > And now the validators works. > > Still wondering if IS_DECIMAL_IN_RANGE as to be explicitly define since the > decimal(4,2)

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
Ok, I think I wrongly define the IS_DECIMAL_IN_RANGE I set it to (0,99.99) And now the validators works. Still wondering if IS_DECIMAL_IN_RANGE as to be explicitly define since the decimal(4,2) were already available Richard On Wed, Nov 17, 2010 at 4:06 PM, Richard Vézina wrote: > Just

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
Just to be sure... Data are entered in english... Mean if we entered exactly this in the form fiel : 123.123 On Wed, Nov 17, 2010 at 3:59 PM, Jonathan Lundell wrote: > On Nov 17, 2010, at 12:26 PM, mdipierro wrote: > > > > could be. Not sure what that means for decimal numbers. > > FWIW, I took a

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Jonathan Lundell
On Nov 17, 2010, at 12:26 PM, mdipierro wrote: > > could be. Not sure what that means for decimal numbers. FWIW, I took a look at the Python decimal module, and it requires '.' as the decimal separator. So any conversion is going to have to happen before Decimal gets the string. > > On Nov 1

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
The french in the ticket should comes from the ubuntu locales setting, I see no python packages related to the local... Richard On Wed, Nov 17, 2010 at 3:43 PM, Richard Vézina wrote: > No change with nav set to en-us and with firefox. > > Richard > > > On Wed, Nov 17, 2010 at 3:35 PM, Richard V

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
No change with nav set to en-us and with firefox. Richard On Wed, Nov 17, 2010 at 3:35 PM, Richard Vézina wrote: > In the database table decimal are represented like this : 123.123 > > When I export data the "." is replaced by the comma, but I think that > depend of the local of the system or t

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
In the database table decimal are represented like this : 123.123 When I export data the "." is replaced by the comma, but I think that depend of the local of the system or the local I specified in the pgadmin export panel... What the relation between the local of the database and the and the len

[web2py] Re: decimal validator by default or not

2010-11-17 Thread mdipierro
could be. Not sure what that means for decimal numbers. On Nov 17, 2:07 pm, Richard Vézina wrote: > I use postgresql and local in postgres are : fr_CA.UTF-8 > > Could it be the reason of the problem? > > Richard > > On Wed, Nov 17, 2010 at 2:37 PM, mdipierro wrote: > > BTW... why are you getting

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
I use postgresql and local in postgres are : fr_CA.UTF-8 Could it be the reason of the problem? Richard On Wed, Nov 17, 2010 at 2:37 PM, mdipierro wrote: > BTW... why are you getting the traceback in french? If your python is > localized, could this affect the meaning of . in sqlite? > > On No

[web2py] Re: decimal validator by default or not

2010-11-17 Thread mdipierro
BTW... why are you getting the traceback in french? If your python is localized, could this affect the meaning of . in sqlite? On Nov 17, 9:43 am, Richard Vézina wrote: > Hello, > > I wonder if it is normal that I get ticket in that case : > > Model : > > Field('field1','decimal(4,2)'), > > If I

[web2py] Re: decimal validator by default or not

2010-11-17 Thread mdipierro
what python version? perhaps something has changed in sqlite? this looks like a sqlite error. On Nov 17, 9:43 am, Richard Vézina wrote: > Hello, > > I wonder if it is normal that I get ticket in that case : > > Model : > > Field('field1','decimal(4,2)'), > > If I insert in form generate with crud

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Jonathan Lundell
On Nov 17, 2010, at 9:40 AM, Richard Vézina wrote: > Doesn't neither with IS_DECIMAL_IN_RANGE(0,99), I get the same ticket... The doctest for IS_DECIMAL_IN_RANGE is currently broken (Massimo, I'll send you a patch), but these all pass: >>> IS_DECIMAL_IN_RANGE(0,99)(123.123) (123.

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
Doesn't neither with IS_DECIMAL_IN_RANGE(0,99), I get the same ticket... Richard On Wed, Nov 17, 2010 at 12:24 PM, villas wrote: > Sorry I misunderstood. I think you are right, web2py doesn't validate > it. > -D > > On Nov 17, 5:00 pm, Richard Vézina > wrote: > > I don't want to store 123.123,

[web2py] Re: decimal validator by default or not

2010-11-17 Thread villas
Sorry I misunderstood. I think you are right, web2py doesn't validate it. -D On Nov 17, 5:00 pm, Richard Vézina wrote: > I don't want to store 123.123, I want 99.99 max. > > The problem is that no validator is triggered when entering 123.123... > > Richard > > On Wed, Nov 17, 2010 at 11:53 AM, vi

Re: [web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
I don't want to store 123.123, I want 99.99 max. The problem is that no validator is triggered when entering 123.123... Richard On Wed, Nov 17, 2010 at 11:53 AM, villas wrote: > Hi Richard > > It might depend on the DB, but I believe you would normally need at > least decimal(5,2) to contain

[web2py] Re: decimal validator by default or not

2010-11-17 Thread villas
Hi Richard It might depend on the DB, but I believe you would normally need at least decimal(5,2) to contain 123.456789 With decimal(4,2) I think the max value would be 99.99... Try it... :) -D On Nov 17, 3:44 pm, Richard Vézina wrote: > I forgot to precise that I am under 1.88.2 > > Thanks

[web2py] Re: decimal validator by default or not

2010-11-17 Thread Richard Vézina
I forgot to precise that I am under 1.88.2 Thanks On Wed, Nov 17, 2010 at 10:43 AM, Richard Vézina < ml.richard.vez...@gmail.com> wrote: > Hello, > > I wonder if it is normal that I get ticket in that case : > > Model : > > Field('field1','decimal(4,2)'), > > > If I insert in form generate with

[web2py] Re: Decimal Field omitted in rows.as_dict()

2010-10-22 Thread mdipierro
dal.py needs lots of patches. Lots of stuff has been patched in sql.py but not in dal since June 2010. On Oct 22, 9:14 am, iiijjjiii wrote: > Should dal.py be patched as well? > > On Oct 6, 9:32 am, mdipierro wrote: > > > I i have fixed this (partially) partially since as_dict is used in > > jso

[web2py] Re: Decimal Field omitted in rows.as_dict()

2010-10-22 Thread iiijjjiii
Should dal.py be patched as well? On Oct 6, 9:32 am, mdipierro wrote: > I i have fixed this (partially) partially since as_dict is used in > json serialization and thereforedecimalis converted into float. >

[web2py] Re: Decimal Field omitted in rows.as_dict()

2010-10-06 Thread mdipierro
I i have fixed this (partially) partially since as_dict is used in json serialization and therefore decimal is converted into float. On Oct 5, 4:35 pm, yamandu wrote: > Sure, it was posted. > > On Oct 5, 3:00 pm, mdipierro wrote: > > > This is a bug. Will look into it. Woud you post a bug report

[web2py] Re: Decimal Field omitted in rows.as_dict()

2010-10-05 Thread mdipierro
thanks. It will be taken care of soon. On Oct 5, 4:35 pm, yamandu wrote: > Sure, it was posted. > > On Oct 5, 3:00 pm, mdipierro wrote: > > > This is a bug. Will look into it. Woud you post a bug report on google > > code? > > > On Oct 5, 12:47 pm, yamandu wrote: > > > > I need to pass a dict f

[web2py] Re: Decimal Field omitted in rows.as_dict()

2010-10-05 Thread yamandu
Sure, it was posted. On Oct 5, 3:00 pm, mdipierro wrote: > This is a bug. Will look into it. Woud you post a bug report on google > code? > > On Oct 5, 12:47 pm, yamandu wrote: > > > I need to pass a dict from a row to render a template that is in DB. > > I got error and verified that only decim

[web2py] Re: Decimal Field omitted in rows.as_dict()

2010-10-05 Thread mdipierro
This is a bug. Will look into it. Woud you post a bug report on google code? On Oct 5, 12:47 pm, yamandu wrote: > I need to pass a dict from a row to render a template that is in DB. > I got error and verified that only decimal fields are not being put in > dict when I use: rows.as_dict()

Re: [web2py] Re: decimal validator fail on degree si gn "°", comma "," and hyphen "-" CLOSED

2010-09-28 Thread Richard Vézina
Fixed thank you! Regards Richard On Mon, Sep 27, 2010 at 9:57 PM, mdipierro wrote: > - should be allowed. > , as a separator is not allows. I will change trunk in 5 minutes and > will be able to do IS_DECIMAL_IN_RANGE(dot=','). try it and let us > know. > > other symbols are not allowed. > >

[web2py] Re: decimal validator fail on degree sign " °", comma "," and hyphen "-"

2010-09-27 Thread mdipierro
- should be allowed. , as a separator is not allows. I will change trunk in 5 minutes and will be able to do IS_DECIMAL_IN_RANGE(dot=','). try it and let us know. other symbols are not allowed. On Sep 27, 11:09 am, Richard Vézina wrote: > Hello, > > I am under web2py 1.83.2 and I have those erro

[web2py] Re: Decimal type validator

2010-09-13 Thread mdipierro
in trunk. Thanks again. On Sep 13, 11:53 am, Jonathan Lundell wrote: > On Sep 13, 2010, at 9:42 AM, mdipierro wrote: > > > > > yes please. thanks. > > http://web.me.com/jlundell/filechute/validators.zip > > also IS_INT_IN_RANGE. > > > > > On Sep 13, 11:22 am, Jonathan Lundell wrote: > >> On Sep

Re: [web2py] Re: Decimal type validator

2010-09-13 Thread Jonathan Lundell
On Sep 13, 2010, at 9:42 AM, mdipierro wrote: > > yes please. thanks. http://web.me.com/jlundell/filechute/validators.zip also IS_INT_IN_RANGE. > > On Sep 13, 11:22 am, Jonathan Lundell wrote: >> On Sep 13, 2010, at 8:34 AM, Jonathan Lundell wrote: >> >> >> >>> Massimo, I notice that there

[web2py] Re: Decimal type validator

2010-09-13 Thread mdipierro
yes please. thanks. On Sep 13, 11:22 am, Jonathan Lundell wrote: > On Sep 13, 2010, at 8:34 AM, Jonathan Lundell wrote: > > > > > Massimo, I notice that there's no way to call > > IS_DECIMAL_IN_RANGE(None,None): that is, to ask for a decimal number > > without caring about min/max. That seems w

Re: [web2py] Re: Decimal type validator

2010-09-13 Thread Jonathan Lundell
On Sep 13, 2010, at 8:34 AM, Jonathan Lundell wrote: > > Massimo, I notice that there's no way to call IS_DECIMAL_IN_RANGE(None,None): > that is, to ask for a decimal number without caring about min/max. That seems > wrong to me. The comment says: > The minimum and maximum limits can be No

Re: [web2py] Re: Decimal type validator

2010-09-13 Thread Jonathan Lundell
On Sep 13, 2010, at 4:55 AM, mdipierro wrote: > > Can you help debug? In gluon/validators.py > >def __call__(self, value): >try: >v = decimal.Decimal(str(value)) # << line 725 >... >except (ValueError, TypeError, decimal.InvalidOperation): >

[web2py] Re: Decimal type validator

2010-09-13 Thread mdipierro
Can you help debug? In gluon/validators.py def __call__(self, value): try: v = decimal.Decimal(str(value)) # << line 725 ... except (ValueError, TypeError, decimal.InvalidOperation): pass return (value, self.error_message) why is the

[web2py] Re: Decimal data types?

2010-08-15 Thread mdipierro
The link above is deprecated. The book says yes. That is the final work on it. On 16 Ago, 00:25, Philip wrote: > Does web2py support python decimal data type for fields? > > The info on the web athttp://www.web2py.com/examples/default/dal > suggests the answer is no, but I just wanted to confirm.

[web2py] Re: Decimal data types?

2010-08-15 Thread Rob
Looks like it does: http://web2py.com/book/default/chapter/06?search=decimal On Aug 15, 3:25 pm, Philip wrote: > Does web2py support python decimal data type for fields? > > The info on the web athttp://www.web2py.com/examples/default/dal > suggests the answer is no, but I just wanted to confirm.

[web2py] Re: Decimal vs Float and Documentation

2010-06-01 Thread mdipierro
Before the model in the model file will do. On Jun 1, 3:39 pm, NetAdmin wrote: > In which file do I declare the class? > > Thanks to everyone for their answers. > > On Jun 1, 3:10 pm, mdipierro wrote: > > > There is no need to use SQLCustomType in this case. Decimal is > > supported by web2py ty

[web2py] Re: Decimal vs Float and Documentation

2010-06-01 Thread NetAdmin
In which file do I declare the class? Thanks to everyone for their answers. On Jun 1, 3:10 pm, mdipierro wrote: > There is no need to use SQLCustomType in this case. Decimal is > supported by web2py type='decimal(n,m)' if the underliying database > supports it. The problem is representation

[web2py] Re: Decimal vs Float and Documentation

2010-06-01 Thread mdipierro
There is no need to use SQLCustomType in this case. Decimal is supported by web2py type='decimal(n,m)' if the underliying database supports it. The problem is representation of the number. Try this: class IS_MYDECIMAL(IS_DECIMAL_IN_RANGE): def formatter(self,value): return '%.2f' % value an

[web2py] Re: Decimal

2010-04-27 Thread mdipierro
Field('totalsale', 'decimal(10,8)')) # this is not required, it is automatic db.document.totalsale.requires=IS_DECIMAL() sqlite does not support decimal so this behaves as a double with sqlitle. I am using sqlite. On Apr 27, 9:42 am, greenpoise wrote: > I see a few threads on decimal values. W