Questions tagged [math.round]

21 questions
1
vote
3 answers

I hava a very simple question about Math.round() in javascript

code: let result; result = 2.4999999999999998; console.log(Math.round(result)); result = 2.4999999999999997; console.log(Math.round(result)); The rounding point isn't 5 ? (Although I know that numbers in JavaScript always occupy 64 bits of…
Ale MaGD
  • 17
  • 5
1
vote
1 answer

MidpointRounding in Math.Round not working correctly in C#

The MidpointRound.AwayFromZero overload is supposed to round the 5 up in a rounding situation. EX: Math.Round(1.5, 1, MidpointRounding.AwayFromZero); This rounds 1.5 to 2. However, when I try Math.Round(1.025, 2, MidpointRounding.AwayFromZero); it…
hidden82
  • 59
  • 7
1
vote
1 answer

I'm trying to preview random photos on the site's share link

I used this function in js to open the variable in the head of the html, I don't know if there is a solution or if there is another way to do it. function randomlink() { var links = new Array(3) links[0] =…
1
vote
2 answers

Issue with Math.Round for decimals shows incorrect rounding

I am getting invalid value when performing this Math.Round(0.575, 2, MidpointRounding.AwayFromZero) trying to do midpoint rounding up? Input: Math.Round(0.575, 2, MidpointRounding.AwayFromZero) Expected: 0.58 but getting 0.57 Input:…
0
votes
1 answer

Will Math.round(intA/intB) always return the same on every device?

I'm worried that something like 7/2 might become 3.49999999 instead of 3.5 on some computer then round to 3 instead of 4. Is that possible? I need every computer to re-run the same math exactly. That's the only time I ever have a float:…
Curtis
  • 2,486
  • 5
  • 40
  • 44
0
votes
3 answers

Is there a C# function or overload to Math.Round that will allow abnormal rounding practices?

I have the need to round a number for pricing sort of strangely as follows: the value of an incoming price will be 3 decimal places (ie. 10.333) It is necessary to round the first decimal place up if any number past said first decimal place is…
Gazrok
  • 99
  • 2
  • 8
0
votes
4 answers

Java: Math.round function not working with integer

Looks like there is issue with java's Math.round function, when passing integer value to it. I ran it for couple of inputs but giving suprisingly wrong results. Sample Code: public static void main(String[] args) { …
Aayush Jain
  • 183
  • 1
  • 11
0
votes
2 answers

left-hand side of an assignment must be a variable, property or indexer when trying to round variable and use operator

Code is returning: "The left-hand side of an assignment must be a variable, property or indexer" I'm still new to C# (coming from python), but I understand this issue, however I've got no clue how to fix it I essentially want to have input initially…
elizac
  • 11
  • 3
0
votes
1 answer

Product Calculator - Rounding a function return

I am creating a product calculator for bags of compost. The user inputs the dimensions of their garden, one function returns the actual volume of their garden, another returns the number of bags needed to fill this volume. The Total Bags function…
Thomas
  • 3
  • 1
0
votes
1 answer

"Math.round" is not rounding to the nearest integer correctly

Can someone please kindly explain to me why "Math.round" is not rounding to the nearest integer correctly? I have a 2D array, in which I want to find out the average of each columns. const nums = [[ 20,10,35…
0
votes
1 answer

C# Issue implementing rounding

New to coding and C#. I've written a piece of code that I'm running into issues with rounding out to 2 decimals. My code is designed to take todays date and subtract it by a future date. The code itself works; but I wanted it to look cleaner than…
M.DeMar
  • 9
  • 3
0
votes
0 answers

Javascript Math.round() wrong calculation

I've came across this issue and really can't figure out what i'm doing wrong. So I use math.round to get 2 floating point of a variable. Later on i need to multiply this value *100. But somehow I receive an invalid…
Ceatry
  • 89
  • 2
  • 7
0
votes
1 answer

Math.round method turns thousands into hundreds

I'm trying to create a map-related calculator and I'm having a problem with the Math.Round method. Basically, I want the program to take the real-life length and the length on a map to calculate the scale of said map. After it calculates the scale…
Hain_Z
  • 9
  • 3
0
votes
0 answers

How to round the degrees OpenWeather APIs

I have a script to extract the time, and for a long time I've been trying to round the degrees from 6.27C ° to 6C °. How can I do this?
dzver
  • 1
  • 1
0
votes
1 answer

How to use Math.round to round values returned from JSON object in Vue.js

I am attempting to build a component in Vue 3 with CompositionAPI that returns values to the screen from an json object. So far, I have set up the component to get values from a local data.json file, then return the values to the template. The…
JS_is_awesome18
  • 1,587
  • 7
  • 23
  • 67
1
2