Skip to content

DECIMAL -0.6 can be wrongly transformed to 0.6 in TrinoBigDecimal #29

@liuhhhing

Description

@liuhhhing

I can see from the code below:

https://github.com/trinodb/trino-csharp-client/blob/main/trino-csharp/Trino.Client/Types/BigDecimal.cs#L23

the code below:

public TrinoBigDecimal(string value) { 
    var parts = value.Split('.'); 
    integerPart = BigInteger.Parse(parts[0]); 
    fractionalPart = parts.Length > 1 ? BigInteger.Parse(parts[1]) : BigInteger.Zero; 
    scale = parts.Length > 1 ? parts[1].Length : 0; 
    Validate(); 
}

The line integerPart = BigInteger.Parse(parts[0]); can have the -0.6 case wrongly interpreted as 0.6, the integral part when it is -0, this parse function will make it as 0. The sign information will be lost entirely.

I think there should be a 'Sign' member variable for this class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions