You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2020/10/24 00:13:00 UTC

[jira] [Resolved] (CALCITE-4346) strange result in toString function with bigdecimal type

     [ https://issues.apache.org/jira/browse/CALCITE-4346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julian Hyde resolved CALCITE-4346.
----------------------------------
    Resolution: Duplicate

There is a variation of behaviors. You are not going to convince me that Oracle and Calcite are 'wrong' and MySQL and Hive are 'right', and that we should change Calcite's behavior.

If you want control over the behavior, let's implement the {{FORMAT}} clause of {{CAST}} (see CALCITE-2980) and then you can write {{CAST(x AS VARCHAR FORMAT '0.0')}} or similar.

> strange result in toString function with bigdecimal type
> --------------------------------------------------------
>
>                 Key: CALCITE-4346
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4346
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Zhixiong Chen
>            Priority: Major
>
> In  SqlFunctions the toString function with BigDecimal type will replace 0.1 with .1 .
> But why is this ?
> {code:java}
> public static String toString(BigDecimal x) {
>  final String s = x.toString();
>  if (s.equals("0")) {
>  return s;
>  } else if (s.startsWith("0.")) {
>  // we want ".1" not "0.1"
>  return s.substring(1);
>  } else if (s.startsWith("-0.")) {
>  // we want "-.1" not "-0.1"
>  return "-" + s.substring(2);
>  } else {
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)