rounding

PHP: rounding a number into 16 decimal digits

不羁的心 提交于 2019-12-13 14:18:03
问题 Hi I'm trying to rounding a number into the 16 decimal digits but it only show and doesn't round up till 14 decimal digit . Here's my attempt: <?php $num= 0.16346153846153846; $round = number_format((float)$num, 17, '.', ''); echo $round * -1; ?> OUTPUT: -0.16346153846154 EXPECTED OUTPUT: 0.1634615384615385 I know that float is only 14 decimal digits. Is there any other way around for the 16 decimal digits ? 回答1: You can set this parameters at run-time. 16 digits is usually the maximum value

Rounding a variable to two decimal places C# [duplicate]

Deadly 提交于 2019-12-13 11:51:49
问题 This question already has answers here : How do you round a number to two decimal places in C#? (15 answers) Closed 22 days ago . I am interested in how to round variables to two decimal places. In the example below, the bonus is usually a number with four decimal places. Is there any way to ensure the pay variable is always rounded to two decimal places? pay = 200 + bonus; Console.WriteLine(pay); 回答1: Use Math.Round and specify the number of decimal places. Math.Round(pay,2); Math.Round

Python Pandas DataFrame Rounding of big fraction values [closed]

不羁的心 提交于 2019-12-13 11:11:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 11 months ago . How to round off big fraction values of a pandas DataFrame.I want to round off the "Gaps between male and female score" column of the given Dataframe image. I have tried following: df.astype('int').round() but it doesn't work? Image 回答1: Considering some initial rows of your dataframe, Year Score 0 1990 1

Why Round(Fix(x))?

跟風遠走 提交于 2019-12-13 10:18:57
问题 In the Reflector extract for Microsoft.VisualBasic it references Microsoft.VisualBasic.Conversion.Fix in 3 places not including the Fix(Object) overload. In each case it applies Math.Round to the result. (Especially in DateAdd and DateDiff ; the third use in Choose does subtract 1 , and redundantly cast to Double again before applying Round .) When can Math.Round(Conversion.Fix(x)) <> Conversion.Fix(x) for Double x ? (I'd check the Reference Source myself but I can't find a download that does

Rounding of the numeric values

梦想的初衷 提交于 2019-12-13 09:45:29
问题 I want to round of the values of two columns: select a.region as "Regions", a.suminsured,2 as "SumInsured" , a.suminsured/b.sum*100 as pct from ( SELECT region, sum(suminsured) as suminsured FROM "Exposure_commune" group by region ) a, (select sum(suminsured) FROM "Exposure_commune") b I want the suminsured and pct columns to come with 2 decimal places. Can someone tell me what I should do? 回答1: Use round() with two parameters, which only works for the data type numeric. While being at it,

How to convert 2 restricted decimal variables to a third variable and vice versa?

谁说我不能喝 提交于 2019-12-13 09:26:12
问题 I have 2 convertor methods as below: private const decimal MaxValidValue = 99.99m; public decimal ConvertABToC(decimal a, decimal b) { return a * b; } public void ConvertCtoAB(decimal c, ref decimal a, ref decimal b) { if (c > MaxValidValue*MaxValidValue) { throw new ApplicationException(); } if (c <= MaxValidValue) { a = 1.00m; b = c; } else { // need to introduce some logic or assumptions here } } There are 3 important things to know: 1) The a and b variables are in the range of 0.00 to 99

How to round a float value [closed]

帅比萌擦擦* 提交于 2019-12-13 09:08:41
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to round a float value as follows: (0.11 + 0.22 + 0.23 / 3).round(2) Does anyone know if there is other effective way to round up? 回答1: If you always want to round up and never down, you can do this:

C: How do I make a number always round up

孤街浪徒 提交于 2019-12-13 08:45:17
问题 I'm wanting to make a function that calculates a cost based on time. For any time less than three hours, it would return a flat rate charge of $2. For each hour or part of an hour over that, it would charge an additional $0.50. Hours are input by user as a float data type to 2 decimal places. How can I make it to where it will always round up the time to a whole hour? Here's the code I have so far for the function: int calculateCharges(float hours) { if (hours <= 3){ return 2.00 } else 回答1:

TSQL number rounding issue

不想你离开。 提交于 2019-12-13 08:10:23
问题 I have a piece of code: IF OBJECT_ID(N'dbo.rounding_testing') IS NOT NULL DROP FUNCTION dbo.rounding_testing; GO CREATE FUNCTION dbo.rounding_testing ( @value FLOAT, @digit INT ) RETURNS FLOAT BEGIN DECLARE @factor FLOAT, @result FLOAT; SELECT @factor = POWER(10, @digit); SELECT @result = FLOOR(@value * @factor + 0.4); RETURN @result; END; GO SELECT dbo.rounding_testing(5.7456, 3); SELECT FLOOR(5.7456 * 1000 + 0.4); The results are: 5745 5746 I'm expecting two 5746. I tried to debug the

Dithering child elements' dimensions to fill a parent element

微笑、不失礼 提交于 2019-12-13 07:00:02
问题 Say I have a parent div with width 500px. It has 13 child elements that should fill its width. If I give each child element a width of 500 / 13 = 38.46... pixels, the browser will floor the pixel values, so I end up with 13 elements that take up a total of 38 * 13 = 494 pixels. There will be 6 pixels on the right side of the parent div that are not filled. Is there an easy way to dither the child element widths so that the remainder (6 pixels) is distributed among some of the child elements,