Undesired number formatting when using custom culture

Posted by: bernardo on 4 November 2019, 1:57 pm EST

  • Posted 4 November 2019, 1:57 pm EST

    Hi there,

    The app on which I am working now supports internationalization, so users now should be able to use different number formats on the spreadsheets. For this feature, we set a new Culture that Spread seems to understand and sometimes properly parse.

    For new entries, it comprehends the value of the input and respects the format. The problem happens when an older input which uses “.” as decimal separator has its separator updated to “,”.

    For example, with the new culture, if a user inputs “1.1” at first and then presses “Enter”, and then edits the cell and change it to “1,1”, Spreadjs will round it to “1” (check out the code below).

    Such behavior does not occur when the “en” culture is set. How does one do to make the custom culture work flawless as “en”?

    Regards,

    
    <!DOCTYPE html>
    <html>
    
    <head>
        <title>Spread HTML test page</title>
    
        <script src="gcspread.sheets.all.9.40.20161.0.min.js" type="text/javascript"></script>
        <script type="text/javascript">
    
            window.onload = function () {
                var spread = new GcSpread.Sheets.Spread(document.getElementById("spreadContainer"));
                setupSpreadJsCulture();
                var activeSheet = spread.getActiveSheet();
            }
    
            var setupSpreadJsCulture = function () {
    
                var myCulture = new GcSpread.Sheets.CultureInfo();
    
                myCulture.currencySymbol = "R$";
                myCulture.numberDecimalSeparator = ",";
                myCulture.numberGroupSeparator = ".";
                myCulture.arrayGroupSeparator = ";";
                myCulture.listSeparator = ";";
                myCulture.arrayListSeparator = "/";
    
                myCulture.abbreviatedMonthNames = ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez", ""];
                myCulture.abbreviatedDayNames = ["dom", "seg", "ter", "qua", "qui", "sex", "sáb"];
                myCulture.abbreviatedMonthGenitiveNames = ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez", ""];
                myCulture.dateSeparator = "/";
                myCulture.dayNames = ["domingo", "segunda-feira", "terça-feira", "quarta-feira", "quinta-feira", "sexta-feira", "sábado"];
                myCulture.fullDateTimePattern = "dddd, d' de 'MMMM' de 'yyyy HH:mm:ss";
                myCulture.longDatePattern = "dddd, d' de 'MMMM' de 'yyyy";
                myCulture.longTimePattern = "HH:mm:ss";
                myCulture.monthDayPattern = "dd' de 'MMMM";
                myCulture.monthNames = ["janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro", ""];
                myCulture.monthGenitiveNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro", ""];
                myCulture.rFC1123Pattern = "ddd, dd MMM yyyy HH\':\'mm\':\'ss \'GMT\'";
                myCulture.shortDatePattern = "dd/MM/yyyy";
                myCulture.shortTimePattern = "HH:mm";
                myCulture.sortableDateTimePattern = "yyyy-MM-dd HH:mm:ss";
                myCulture.universalSortableDateTimePattern = "yyyy\'-\'MM\'-\'dd HH\':\'mm\':\'ss\'Z\'";
                myCulture.yearMonthPattern = "MMMM' de 'yyyy";
    
                myCulture.isReadOnly = true;
                myCulture.calendarIsReadOnly = true;
    
                GcSpread.Sheets.addCultureInfo("pt_BR", myCulture);
                GcSpread.Sheets.Culture("pt_BR");
    
                GcSpread.Sheets._DateTimeHelper._parseDate = function (value, cultureInfo, args) {
    
                    //--- If is a number, return null, so that we don't format this cell as date
                    var parseNumberResult = GcSpread.Sheets._NumberHelper.__parseNumber(value, cultureInfo);
                    if (!_.isNaN(parseNumberResult)) {
                        return null;
                    }
    
                    if (value != null && value.trim() != "") {
    
                        value = value.trim();
    
                        if (value.length < 9) {
                            return moment(value, "DD/MM/YYYY").toDate();
                        } else {
                            return moment(value, "DD/MM/YYYY HH:mm:ss").toDate();
                        }
    
                    }
    
                    return new Date();
                }
    
            }
        </script>
    </head>
    
    <body>
        <div id="spreadContainer" style="width: 600px; height: 400px; border: 1px solid gray">
        </div>
    </body>
    
    </html>
    
    
  • Posted 5 November 2019, 1:54 am EST

    Hi Bernardo,

    The issue seems to be fixed with the latest spread version 12.2.5. Please update to the latest version and let us know if you still face any issues.

    You may verify the same using the following sample which uses the latest spread build: https://codesandbox.io/s/spread-js-starter-0f4q4

    Regards

    Sharad

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels