[RESOLVED] format excel cell for 2 decimal places
I want to put some value in to my excel worksheet cell.
i want to format the cell to display only for 2 decimal places
for example
VB Code:
dim s as long
s=1.236767
.Cells(1, 4).Value = s
so i want the value for .Cells(1, 4).Value should be 1.23
how can i format this??i am using late binding
thanks
wizkid
Re: format excel cell for 2 decimal places
I'm not sure I'm understanding your question correctly, but if I am, then you want 2 decimal spaces in a given range right?
In that case, just use the numberformat
VB Code:
range(yourrangehere).NumberFormat = "###,##0.00"
if you add another 0(zero) you get 3 decimal spaces - by removing the ,(comma) you won't get a 1.000 separator.
Hope this helps
/Nick
Re: format excel cell for 2 decimal places
already i tried with this
but it is not working.i am getting error like property not valid
Re: format excel cell for 2 decimal places
Can i see you code?
I normally use numberformat, but I haven't experienced errors
Re: format excel cell for 2 decimal places
thanks direktoren
i got the answer
formatnumber is the property to format the number.
.Cells(stylecode_colorcode, 4).Value = FormatNumber(percen, 3)
Re: format excel cell for 2 decimal places
Hi Nick,
I need one help for the excel. How to set 3 decimal place and comma (,) in particulars cell in excel using vb.net.
Re: [RESOLVED] format excel cell for 2 decimal places
you should have started a new thread for this question, it may well be that nick is no longer monitoring this thread
the basic is
Code:
range("b1").NumberFormat = "0.000"
i believe that if your locale setting is to use a comma as the decimal placeholder, it will interpret this correctly, if as mine the locale setting for decimal is period i can not really test
trying to force it display differently to the locale setting may present some problem, but you can try replacing the period with a comma if need be