Announcement

Collapse
No announcement yet.

Decimal rounding to 1

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Decimal rounding to 1

    The following code, should display "(1/3)*3 = 0.9999999999999999999999999999" to the console, as a normal C# application does.

    decimal dividend = Decimal.One;
    decimal divisor = 3;
    Console.WriteLine("(1/3) * 3 = {0}", dividend / divisor * divisor);
    The cross compiled JavaScript version displays instead: "(1/3)*3 = 1". This value should not be rounded to 1, it should be the same value as a C# Application (0.9999...), am I right?

    #2
    Hi gioretti,

    Welcome to Bridge!

    Thanks for letting us know about this issue. I have reproduced and we will investigate.

    https://deck.net/a26e6c3490e1fd2ff503c39fa38a4102

    https://dotnetfiddle.net/5HVFt0

    public class Program
    {
        public static void Main()
        {
            decimal dividend = Decimal.One;
            decimal divisor = 3;
    
            var val = dividend / divisor * divisor;
    
            Console.WriteLine("(1/3) * 3 = {0}", val);
        }
    }

    Comment

    Working...
    X