Re: [web2py] Re: Formatting numbers in view

2017-10-30 Thread Gualter Portella
Thank, Paolo! I will take a look at the API.

2017-10-30 19:16 GMT-02:00 Paolo Caruccio :

> If it is feasible for you, you could use *Intl.NumberFormat* (
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/
> Reference/Global_Objects/NumberFormat) javascript Internationalization
> API.
>
>
>
> Il giorno lunedì 30 ottobre 2017 18:59:27 UTC+1, Gualter Portella ha
> scritto:
>>
>> Dear all,
>>
>> I have been trying to reformat the numbers retrieved from the DB into the
>> format used in my country (Brazil).
>>
>> I want to change decimals to ',' and thousands to '.'
>>
>> The thing is that the only solution that I can figure out is in Python 3
>> - I am am new to programming and webdev, like this:
>>
>> In the model:
>>swap_separators = { ord('.'):',', ord(','):'.' }
>>
>> In the view:
>>
>>{{ ativos = format(float(table.column), '0.2f') }}
>>
>>   {{=format(float(ativos), ',').translate(swap_separators)}}
>>
>>
>> I am currently working with Python 3. My question is: will this  solution
>> work when I deploy the app in a host that uses Python 2 for web2py?
>>
>> If someone else has asked or posted a solution for this before, please
>> direct me to it. Otherwise, any help is really appreciated.
>>
>> Cheers,
>>
>>
>> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/Us-pjfme8zY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Gualter Portella

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: Formatting numbers in view

2017-10-30 Thread Desobediente
Cross posting my answer in the brazilian list

money string formatting in python2

currency = str('U$$')
value = float(0.02)
formatted_value = '{:,.2f}'.format(value)
print(' '.join([currency, formatted_value]))

cryptocurrency formating (8 decimals)

currency = str('BTC')
value = float(0.0327)
formatted_value = '{:,.8f}'.format(value)
what_to_print = ' '.join([formatted_value, currency])

-- 
iuri.neocities.org

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Formatting numbers in view

2017-10-30 Thread Paolo Caruccio
If it is feasible for you, you could use *Intl.NumberFormat* (
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
 
javascript Internationalization API.



Il giorno lunedì 30 ottobre 2017 18:59:27 UTC+1, Gualter Portella ha 
scritto:
>
> Dear all,
>
> I have been trying to reformat the numbers retrieved from the DB into the 
> format used in my country (Brazil).
>
> I want to change decimals to ',' and thousands to '.'
>
> The thing is that the only solution that I can figure out is in Python 3 - 
> I am am new to programming and webdev, like this:
>
> In the model:
>swap_separators = { ord('.'):',', ord(','):'.' }
>
> In the view:
>
>{{ ativos = format(float(table.column), '0.2f') }}
>
>   {{=format(float(ativos), ',').translate(swap_separators)}}
>
>
> I am currently working with Python 3. My question is: will this  solution 
> work when I deploy the app in a host that uses Python 2 for web2py?
>
> If someone else has asked or posted a solution for this before, please 
> direct me to it. Otherwise, any help is really appreciated.
>
> Cheers,
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.