Connecting Tech Pros Worldwide Forums | Help | Site Map

Find out number of decimal places

Newbie
 
Join Date: Sep 2007
Posts: 8
#1: Sep 25 '07
Hi,

I hope you're all well.

I need to right justify some figures in a list box and the only way I seem to be able to do it is by using the number as text and doing something like this in a query.

Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.accountID, string(8-len(ref1)," ") & [ref1] AS Expr1,etc, etc
The above query for one of the columns, looks at how many characters there are and then adds spaces at the beginning to make it 8 characters long (the max for field in table)

However, I need them all to have 3 decimal places.

So, I need a calc that does the above but, before it calculates that, it needs to make sure that there is a decimal point present AND that if adds in 000's to make it up to 3 decimal places

if number = 1 then add in ".000" make it 1.000
if number = 1.3 then add "00" to make it 1.300
if number = 1.35 then add "0" to make it 1.350

Anyone have any ideas what calc I can use in my query?

Thanks

Newbie
 
Join Date: Sep 2007
Posts: 8
#2: Sep 25 '07

re: Find out number of decimal places


Found it!

Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.accountID, string(8-len(FormatNumber([ref1],3))," ") & FormatNumber([ref1],3) AS Expr1
Scott Price's Avatar
Moderator
 
Join Date: Jul 2007
Location: Seattle, WA
Posts: 1,314
#3: Sep 25 '07

re: Find out number of decimal places


Hi Matt! Glad you found your own answer! The likely reason no one else has tried to answer this is because you posted (inadvertently) in the Articles section instead of the main forum!

I'll move your thread across so all can see.

Regards,
Scott
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#4: Sep 26 '07

re: Find out number of decimal places


Forget that Matt - You need :
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.accountID, Right(Format([Ref1], '   0.000'), 8) AS Expr1
Reply