#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Rounding

How do you round to 1 decimal place in code?
I know how to put a round formula in a cell, but I have a
value and need to reference, but not display, the rounded
result of.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Rounding

Sub RoundTest()
Dim x
x = 1.2345
Debug.Print Round(x, 1)
End Sub

--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"



"Tasmin" wrote in message
...
How do you round to 1 decimal place in code?
I know how to put a round formula in a cell, but I have a
value and need to reference, but not display, the rounded
result of.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Rounding

be aware that VBA's Round() method and XL's ROUND() function differ in
how they round numbers that have 5 as their terminal digit. XL's ROUND()
always rounds away from zero (i.e., arithmetic rounding) and VBA's Round
rounds to the nearest even number (i.e., "banker's rounding"):


x Round(x,1) =ROUND(x,1)
1.05 1.0 1.1
1.15 1.2 1.2
1.25 1.2 1.3
1.35 1.4 1.4



In article , "Andy Wiggins" <xx
wrote:

Sub RoundTest()
Dim x
x = 1.2345
Debug.Print Round(x, 1)
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 837
Default Rounding

Also be aware that the VBA round function was only introduced in Excel
2000 (OP did not specify version), and does not support negative values
for numdecimalplaces. You can call the worksheet Round function via
Application.Round(x,1)

Jerry

Andy Wiggins wrote:

Sub RoundTest()
Dim x
x = 1.2345
Debug.Print Round(x, 1)
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ROUNDING FORMULA =ROUND(B12/$B$10,1) ROUNDING TO HIGH SunshineinFt.Myers[_2_] Excel Worksheet Functions 7 March 5th 09 06:41 PM
rounding up or down Eqa Excel Discussion (Misc queries) 12 December 24th 07 04:47 AM
I need a formula with rounding up & rounding down to the nearest . Tony Kay Excel Worksheet Functions 3 May 29th 07 11:13 PM
Rounding El_Melenero Excel Discussion (Misc queries) 0 November 23rd 05 08:06 PM
Rounding Graham Aird Excel Discussion (Misc queries) 4 November 17th 05 05:30 PM


All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"