prices

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

prices

gearond
Using solr 1.4.

I have a price in my schema. Currently it's a tfloat. Somewhere along the way
from php, json, solr, and back, extra zeroes are getting truncated along with
the decimal point for even dollar amounts.

So I have two questions, neither of which seemed to be findable with google.

A/ Any way to keep both zeroes going inito a float field? (In the analyzer, with
XML output, the values are shown with 1 zero)
B/ Can strings be used in range queries like a float and work well for prices?


 Dennis Gearon


Signature Warning
----------------
It is always a good idea to learn from your own mistakes. It is usually a better
idea to learn from others’ mistakes, so you do not have to make them yourself.
from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'


EARTH has a Right To Life,
otherwise we all die.

Reply | Threaded
Open this post in threaded view
|

Re: prices

Yonik Seeley-2-2
On Fri, Feb 4, 2011 at 12:56 PM, Dennis Gearon <[hidden email]> wrote:

> Using solr 1.4.
>
> I have a price in my schema. Currently it's a tfloat. Somewhere along the way
> from php, json, solr, and back, extra zeroes are getting truncated along with
> the decimal point for even dollar amounts.
>
> So I have two questions, neither of which seemed to be findable with google.
>
> A/ Any way to keep both zeroes going inito a float field? (In the analyzer, with
> XML output, the values are shown with 1 zero)
> B/ Can strings be used in range queries like a float and work well for prices?

You could do a copyField into a stored string field and use the tfloat
(or tint and store cents)
for range queries, searching, etc, and the string field just for display.

-Yonik
http://lucidimagination.com




>
>  Dennis Gearon
>
>
> Signature Warning
> ----------------
> It is always a good idea to learn from your own mistakes. It is usually a better
> idea to learn from others’ mistakes, so you do not have to make them yourself.
> from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'
>
>
> EARTH has a Right To Life,
> otherwise we all die.
>
>
Reply | Threaded
Open this post in threaded view
|

RE: prices

Jonathan Rochkind
Your prices are just dollars and cents? For actual queries, you might consider an int type rather than a float type.  Multiple by a hundred to put it in the index, then multiply your values in queries by a hundred before putting them in the query.  Same for range facetting, just divide by 100 before display of anything you get back.

Fixed precision values like price values aren't really floats or don't really need floats, and floats sometimes do weird things, as you've noticed.

Alternately if your problem is simply that you want to display "2.0" as "2.00" rather than "2" or "2.0", that is something for you to take care of in your PHP app that does the display. PHP will have some function for formatting numbers and saying with what precision you want to display.

There is no way to keep two trailing zeroes 'in' a float field, because "2.0" or "2." is the same value as "2.00" or "2.000000", so they've all got the same internal representation in the float field. There is no way I know to tell Solr what precision to render floats with in it's responses.

________________________________________
From: [hidden email] [[hidden email]] On Behalf Of Yonik Seeley [[hidden email]]
Sent: Friday, February 04, 2011 1:49 PM
To: [hidden email]
Subject: Re: prices

On Fri, Feb 4, 2011 at 12:56 PM, Dennis Gearon <[hidden email]> wrote:

> Using solr 1.4.
>
> I have a price in my schema. Currently it's a tfloat. Somewhere along the way
> from php, json, solr, and back, extra zeroes are getting truncated along with
> the decimal point for even dollar amounts.
>
> So I have two questions, neither of which seemed to be findable with google.
>
> A/ Any way to keep both zeroes going inito a float field? (In the analyzer, with
> XML output, the values are shown with 1 zero)
> B/ Can strings be used in range queries like a float and work well for prices?

You could do a copyField into a stored string field and use the tfloat
(or tint and store cents)
for range queries, searching, etc, and the string field just for display.

-Yonik
http://lucidimagination.com




>
>  Dennis Gearon
>
>
> Signature Warning
> ----------------
> It is always a good idea to learn from your own mistakes. It is usually a better
> idea to learn from others’ mistakes, so you do not have to make them yourself.
> from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'
>
>
> EARTH has a Right To Life,
> otherwise we all die.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: prices

gearond
In reply to this post by Yonik Seeley-2-2
That's a good idea, Yonik. So, fields that aren't stored don't get displayed, so
the float field in the schema never gets seen by the user. Good, I like it.

 Dennis Gearon


Signature Warning
----------------
It is always a good idea to learn from your own mistakes. It is usually a better
idea to learn from others’ mistakes, so you do not have to make them yourself.
from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'


EARTH has a Right To Life,
otherwise we all die.



----- Original Message ----
From: Yonik Seeley <[hidden email]>
To: [hidden email]
Sent: Fri, February 4, 2011 10:49:42 AM
Subject: Re: prices

On Fri, Feb 4, 2011 at 12:56 PM, Dennis Gearon <[hidden email]> wrote:

> Using solr 1.4.
>
> I have a price in my schema. Currently it's a tfloat. Somewhere along the way
> from php, json, solr, and back, extra zeroes are getting truncated along with
> the decimal point for even dollar amounts.
>
> So I have two questions, neither of which seemed to be findable with google.
>
> A/ Any way to keep both zeroes going inito a float field? (In the analyzer,
>with
> XML output, the values are shown with 1 zero)
> B/ Can strings be used in range queries like a float and work well for prices?

You could do a copyField into a stored string field and use the tfloat
(or tint and store cents)
for range queries, searching, etc, and the string field just for display.

-Yonik
http://lucidimagination.com




>
>  Dennis Gearon
>
>
> Signature Warning
> ----------------
> It is always a good idea to learn from your own mistakes. It is usually a
>better
> idea to learn from others’ mistakes, so you do not have to make them yourself.
> from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'
>
>
> EARTH has a Right To Life,
> otherwise we all die.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: prices

Lance Norskog-2
Jonathan- right in one!

Using floats for prices will lead to madness. My mortgage UI kept
changing the loan's interest rate.

On Fri, Feb 4, 2011 at 12:13 PM, Dennis Gearon <[hidden email]> wrote:

> That's a good idea, Yonik. So, fields that aren't stored don't get displayed, so
> the float field in the schema never gets seen by the user. Good, I like it.
>
>  Dennis Gearon
>
>
> Signature Warning
> ----------------
> It is always a good idea to learn from your own mistakes. It is usually a better
> idea to learn from others’ mistakes, so you do not have to make them yourself.
> from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'
>
>
> EARTH has a Right To Life,
> otherwise we all die.
>
>
>
> ----- Original Message ----
> From: Yonik Seeley <[hidden email]>
> To: [hidden email]
> Sent: Fri, February 4, 2011 10:49:42 AM
> Subject: Re: prices
>
> On Fri, Feb 4, 2011 at 12:56 PM, Dennis Gearon <[hidden email]> wrote:
>> Using solr 1.4.
>>
>> I have a price in my schema. Currently it's a tfloat. Somewhere along the way
>> from php, json, solr, and back, extra zeroes are getting truncated along with
>> the decimal point for even dollar amounts.
>>
>> So I have two questions, neither of which seemed to be findable with google.
>>
>> A/ Any way to keep both zeroes going inito a float field? (In the analyzer,
>>with
>> XML output, the values are shown with 1 zero)
>> B/ Can strings be used in range queries like a float and work well for prices?
>
> You could do a copyField into a stored string field and use the tfloat
> (or tint and store cents)
> for range queries, searching, etc, and the string field just for display.
>
> -Yonik
> http://lucidimagination.com
>
>
>
>
>>
>>  Dennis Gearon
>>
>>
>> Signature Warning
>> ----------------
>> It is always a good idea to learn from your own mistakes. It is usually a
>>better
>> idea to learn from others’ mistakes, so you do not have to make them yourself.
>> from 'http://blogs.techrepublic.com.com/security/?p=4501&tag=nl.e036'
>>
>>
>> EARTH has a Right To Life,
>> otherwise we all die.
>>
>>
>
>



--
Lance Norskog
[hidden email]