|
-
Feb 21st, 2006, 07:33 AM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 21st, 2006, 07:46 AM
#2
Lively Member
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
-
Feb 21st, 2006, 07:51 AM
#3
Thread Starter
Hyperactive Member
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
-
Feb 21st, 2006, 07:54 AM
#4
Lively Member
Re: format excel cell for 2 decimal places
Can i see you code?
I normally use numberformat, but I haven't experienced errors
-
Feb 21st, 2006, 08:02 AM
#5
Thread Starter
Hyperactive Member
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)
-
Sep 6th, 2019, 12:55 AM
#6
New Member
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.
-
Sep 6th, 2019, 04:09 AM
#7
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|