Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReplicateString; is there a function ReplicateNumber too? 1

Status
Not open for further replies.

yehong

Programmer
Sep 22, 2003
291
US
CR 8.5 and SQL Server 2000.

I have two fields:
FormatType and Result. The FormateType has the format information of the Result field. Like if FormatType is 0.00, the Result should be 0.00, if FormatType is 0.0000, the Result should be 0.0000. I have created this function:

dim decpos as number
dim rdec as string
dim FormatType as string

' say FormatType ="1.2345"
' say the Result value is 52.7450

If Len(FormatType )<=1 Then /because no need to change format
formula={table.Result}
end if

if "." in FormatType then
decpos=instr(Trim(FormatType ),".")
rdec=right(FormatType ,Len(FormatType )-decpos)
formula=totext(toNumber(Result),"###."&ReplicateString("0",Len(rdec)))
end if

I am getting Result=52.7400, I want to be able to see it as 52.7450. How should I tweak this formula to get correct formated result?

Or any better way of doing this ?

Thanks
 
I think you could right click on the number field->format field->number->customize->decimals->x+2 and enter:

select {table.formattype}
case "1" : 0
case "1.2" : 1
case "1.23" : 2
case "1.234" : 3
case "1.2345" : 4 //etc.
default : 0 //or use the number of decimals you want as the default

Substitute the correct formattype values. This assumes that the format type field uses values consistently to mean the number of decimals, e.g., 3 decimals are always represented by "1.234" or whatever the correct value is for 3 decimals in your database.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top