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: ysee...@gmail.com [ysee...@gmail.com] On Behalf Of Yonik Seeley 
[yo...@lucidimagination.com]
Sent: Friday, February 04, 2011 1:49 PM
To: solr-user@lucene.apache.org
Subject: Re: prices

On Fri, Feb 4, 2011 at 12:56 PM, Dennis Gearon <gear...@sbcglobal.net> 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 via email to