Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
recuperar dados do banco
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Daniel Vilar  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 2:56 pm
From: Daniel Vilar <fvcdan...@gmail.com>
Date: Mon, 17 Sep 2012 15:56:26 -0300
Local: Mon, Sep 17 2012 2:56 pm
Subject: recuperar dados do banco

Pessoal, estou recuperando dados do banco mas está vindo errado!
ex:
  no banco: 0.07
  retorna : 0.07000000000000001

Este erro ocorre tanto no console quanto na view!

alguns valores ele retorna correto mas outros ele traz esse lixo.

Estou usando o oracle_enhanced_adapter com oci-8.

Algum sabe o que é isto?

Att,

CARDOSO, Daniel Fernandes Vilar.
Analista de Sistemas.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Douglas Camata  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 2:57 pm
From: Douglas Camata <d.cam...@gmail.com>
Date: Mon, 17 Sep 2012 15:57:15 -0300
Local: Mon, Sep 17 2012 2:57 pm
Subject: Re: [rails-br] recuperar dados do banco

Isso é a imprecisão da representação do float no sistema binário.

2012/9/17 Daniel Vilar <fvcdan...@gmail.com>

--
Douglas Camata
Graduando em Ciência da Computação (UENF)

Blog: http://douglascamata.net
Github: http://github.com/douglascamata
Twitter: @douglascamata <http://twitter.com/douglascamata>
<http://twitter.com/douglascamata>Skype: douglas_camata
-----------------------------------
Linux User #509211


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Vilar  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:03 pm
From: Daniel Vilar <fvcdan...@gmail.com>
Date: Mon, 17 Sep 2012 16:02:58 -0300
Local: Mon, Sep 17 2012 3:02 pm
Subject: Re: [rails-br] recuperar dados do banco

Blz, como resolve?

Att,

CARDOSO, Daniel Fernandes Vilar.
Analista de Sistemas.

2012/9/17 Douglas Camata <d.cam...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Douglas Camata  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:08 pm
From: Douglas Camata <d.cam...@gmail.com>
Date: Mon, 17 Sep 2012 16:08:27 -0300
Local: Mon, Sep 17 2012 3:08 pm
Subject: Re: [rails-br] recuperar dados do banco

Ai eu não sei. Fiz um trabalhos de cálculo numérico em Python que
precisavam de precisão grande e usei o módulo "decimal" dele. Não sei se
existe um equivalente em Ruby.

2012/9/17 Daniel Vilar <fvcdan...@gmail.com>

--
Douglas Camata
Graduando em Ciência da Computação (UENF)

Blog: http://douglascamata.net
Github: http://github.com/douglascamata
Twitter: @douglascamata <http://twitter.com/douglascamata>
<http://twitter.com/douglascamata>Skype: douglas_camata
-----------------------------------
Linux User #509211


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stclara  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:21 pm
From: Stclara <stcl...@gmail.com>
Date: Mon, 17 Sep 2012 16:21:22 -0300
Local: Mon, Sep 17 2012 3:21 pm
Subject: Re: [rails-br] recuperar dados do banco

Salve.
N�o sei que tipo de campo � e se vc precisa formatado s� na view, mas
para money uso:
number_to_currency(seu_campo).

Se quiser duas casas ap�s o ponto:
format("%.2f", seu_campo).

|[]'s

Stclara.
|||||||||||||

Em 17-09-2012 16:02, Daniel Vilar escreveu:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Vilar  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:26 pm
From: Daniel Vilar <fvcdan...@gmail.com>
Date: Mon, 17 Sep 2012 16:26:35 -0300
Local: Mon, Sep 17 2012 3:26 pm
Subject: Re: [rails-br] recuperar dados do banco

O problema aparentemente é com o bigdecimal.
quando eu faço .to_f ele retorna o valor correto.

Mas essa solução não é mto DRY.

Att,

CARDOSO, Daniel Fernandes Vilar.
Analista de Sistemas.

2012/9/17 Stclara <stcl...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stclara  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:34 pm
From: Stclara <stcl...@gmail.com>
Date: Mon, 17 Sep 2012 16:34:18 -0300
Local: Mon, Sep 17 2012 3:34 pm
Subject: Re: [rails-br] recuperar dados do banco

Ser� que a formata��o de precision no locale n�o resolve? O meu est�
assim (pt_BR.yml):

number:
     format:
       separator: ','
       delimiter: '.'
       precision: 2
       significant: false
       strip_insignificant_zeros: false

     currency:
       format:
         format: '%u %n'
         unit: 'R$'
         separator: ','
         delimiter: '.'
         precision: 2
         significant: false
         strip_insignificant_zeros: false

[]'s

Stclara.

Em 17-09-2012 16:26, Daniel Vilar escreveu:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Vilar  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:42 pm
From: Daniel Vilar <fvcdan...@gmail.com>
Date: Mon, 17 Sep 2012 16:42:51 -0300
Local: Mon, Sep 17 2012 3:42 pm
Subject: Re: [rails-br] recuperar dados do banco

Está igual, não acho que seja isso.
Tem alguma imprecisão com numeros flutuantes como disse o Douglas.
Depois eu irei testar com outras versões do Ruby. Estou usando a 1.9.3-194.

De qualquer forma obrigado!

Att,

CARDOSO, Daniel Fernandes Vilar.
Analista de Sistemas.

2012/9/17 Stclara <stcl...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Douglas Camata  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 3:44 pm
From: Douglas Camata <d.cam...@gmail.com>
Date: Mon, 17 Sep 2012 16:43:56 -0300
Local: Mon, Sep 17 2012 3:43 pm
Subject: Re: [rails-br] recuperar dados do banco

Daniel, a imprecisão vai existir em qualquer versão do Ruby, ela vem do
hardware. Você pode, e deve, formatar os floats que for usar.

2012/9/17 Daniel Vilar <fvcdan...@gmail.com>

--
Douglas Camata
Graduando em Ciência da Computação (UENF)

Blog: http://douglascamata.net
Github: http://github.com/douglascamata
Twitter: @douglascamata <http://twitter.com/douglascamata>
<http://twitter.com/douglascamata>Skype: douglas_camata
-----------------------------------
Linux User #509211


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Eilert  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 4:46 pm
From: Stephen Eilert <spedr...@gmail.com>
Date: Mon, 17 Sep 2012 17:46:11 -0300
Local: Mon, Sep 17 2012 4:46 pm
Subject: Re: [rails-br] recuperar dados do banco

2012/9/17 Daniel Vilar <fvcdan...@gmail.com>

> Blz, como resolve?

Não "resolve". Não existe representação exata em ponto-flutuante na base 2
para 0.07 (http://www.wolframalpha.com/input/?i=0.07+to+base+2)

Ou ainda:

$ irb

> printf("%.50f", 0.07)

0.07000000000000000666133814775093924254179000854492 => nil

O problema aparentemente é com o bigdecimal.

> quando eu faço .to_f ele retorna o valor correto.

Não, piorou, ele apenas está exibindo arredondado. BigDecimal consegue
representar números com precisão arbitrária (não usa o hardware para isso),
mas você vai ter que se assegurar que tudo está trabalhando com BigDecimal
(ou equivalente, no caso do banco).

E não tente fazer coisas do tipo:

BigDecimal.new("0.07") + 0.1 => ele vai fazer cast pra float, pra depois
fazer a soma. No IRB vai aparecer como 0.17, mas isso é só porque ele está
arredondando/truncando o resultado pra você para duas casas decimais.

> BigDecimal.new("0.07") + 0.1

 => 0.17

> printf("%.50f", (BigDecimal.new("0.07") + 0.1))

0.17000000000000001221245327087672194465994834899902 => nil

Dito isso, a não ser que você esteja trabalhando com valores monetários
(que não devem usar float mesmo) ou seja resultado de inúmeras operações em
ponto flutuante, isso não têm importância. Formate antes de imprimir para o
usuário com a precisão que você quer.

Recomendo ler um pouco mais sobre representação de números em ponto
flutuante (base 2). Você vai esbarrar com problemas desse tipo de vez em
quando - por exemplo, na hora de comparar 2 Floats. Ruby é bonzinho e tenta
usar Float::EPSILON pra isso, mas nem sempre é o valor correto para seu
caso.

-- Stephen

*"Kids these days.*
*Whatever happened to hard work?"*

       -- Joel Spolsky, The perils of javaschools


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Vilar  
View profile   Translate to Translated (View Original)
 More options Sep 17 2012, 5:00 pm
From: Daniel Vilar <fvcdan...@gmail.com>
Date: Mon, 17 Sep 2012 18:00:53 -0300
Local: Mon, Sep 17 2012 5:00 pm
Subject: Re: [rails-br] recuperar dados do banco

Galera, obrigado pela ajuda. Deu para entender o que aconteceu. Este campo
é referente a um percentual que e eu já estou contornando o problema na
view.

Obrigado.

Att,

CARDOSO, Daniel Fernandes Vilar.
Analista de Sistemas.

2012/9/17 Stephen Eilert <spedr...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »