GIMP Chat
http://gimpchat.com/

python "str()" vs tiny-fu "number->string"
http://gimpchat.com/viewtopic.php?f=8&t=12702
Page 1 of 1

Author:  dinasset [ Mon Jun 22, 2015 9:06 am ]
Post subject:  python "str()" vs tiny-fu "number->string"

GIMP Version: 2.8.14
Operating System: Windows
GIMP Experience: Basic Level



@Ofnuts
I came back just a little to Python and it seems to me that the simple use of the Python built-in function str return a decimal number in a format acceptable to G'MIC, without asking any specific editing; I mean: if my filter calculates a value from a,b,c such as value = (a+b)/c the returned value is:
iiiiiii.ddddd
the whole part + a dot + the decimal part
provided c has decimals
this consideration came out from a few simple tests
using a=1250, b=750, c=3000 the result value seems to be only 0, but
using a=1250, b=750, c=3000.00 the result value comes out as 0.666666666
is it really so simple to interface G'MIC from Python?
or did I miss something?
thanks

Author:  paynekj [ Mon Jun 22, 2015 9:36 am ]
Post subject:  Re: python "str()" vs tiny-fu "number->string"

Make sure at least one of your variables is a float, otherwise they get presumed to be integers:

>>> a = 1250
>>> b = 750
>>> c =3000
>>> (a + b)/c
0
>>> (a + b)/(c * 1.0)
0.6666666666666666
>>> (a + b)/ float(c)
0.6666666666666666
>>> a = float(1250)
>>> (a + b)/c
0.6666666666666666

Author:  dinasset [ Mon Jun 22, 2015 10:14 am ]
Post subject:  Re: python "str()" vs tiny-fu "number->string"

thanks Kevin
this confirms my simple test above (where I set c=3000 result was integer 0, where I set c=3000.00 result was float 0.666666...)
I'm curious to know from users of python whether:
- the integer part is always expressed as a sequence of digits without any "disturbing" editing char
- the integer part is always separated by a decimal point (the only format accepted by G'MIC)
so that a value of 100000 divided by a value of 3.0 (float) gives in any local system the result as 33333.3333333333333333

Author:  ofnuts [ Mon Jun 22, 2015 5:02 pm ]
Post subject:  Re: python "str()" vs tiny-fu "number->string"

Yes, as far as I can tell from the docs and some experimenting:
  • Python uses the C locale by default (the decimal separator is a dot and there is no grouping)
  • You can set Python to use the user's locale or another locale you specify, but even then, str() and plain formating of numbers ("%3.2f" % 1234.5678) will still use the C locale, only the functions in the locale module are affected by this.

Author:  dinasset [ Tue Jun 23, 2015 1:31 am ]
Post subject:  Re: python "str()" vs tiny-fu "number->string"

thanks Ofnuts
I will prepare my first Python+G'MIC filter soon

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/