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!

ihave a field in table that is numb 2

Status
Not open for further replies.

TIPtip

Programmer
Jan 5, 2004
9
SI
ihave a field in table that is number(double).

when i calculate some stuff i use function

NZ(field,0)

and in some cases it return number(right alligned)
and in some cases it returns like string (left alligned)

do i use right function or where is the problem
 
What you are seeing is not a problem but the nature of the Nz function related to the datatype that is used to return the value.

Nz works with the variant datatype which means it can use any datatype that it is passed.

To quote from the online help.

"You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. Variant".

Since you know that the values returned from Nz will always will always be a zero in the case of being NULL you can use the Val function to force the output to be numeric like this -

Val(Nz(field,0)


Hope this helps,


Steve

 
Good reply by Steve except he forgot the last ")"
Val(Nz(field,0))

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
one more question:

val(NZ(
.[field],0))
returns zero 0

then i calculate : 0 - 123.44 and returns -123 and i lost 0.44.

How to handle this?
 
What makes you think you lose the .44? Is it not showing in a text box or in a field?

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
What is the exact expression that you are using? If you copy the value and paste it into Excel do you see the .44? Have you set any format on the column in the query?

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top