locked
replace text to find parseFloat. RRS feed

  • Question

  • User-240513752 posted
     if (!$.fn.DataTable.isDataTable('#{0}_{1}'.format(courseTypeId, data[0].LocationId))) {
                            $('#{0}_{1}'.format(courseTypeId, data[0].LocationId)).css('display', 'block');
                            table = $('#{0}_{1}'.format(courseTypeId, data[0].LocationId)).DataTable({
                                "ordering": false,
                                "info": false,
                                "searching": false,
                                "lengthChange": false,
                                "pageLength": 20,
                                "autoWidth": false,
                                "data": data,
    
                                "processing" : true,
    
                                "dom": '<"toolbar">frtip',
                                "columns": [
                                     {"render": function (data, type, row, meta) {
                                         return '<input type="checkbox">';
                                     }},
                                    { "data": "CourseStart", "width": "15%" ,"targets": "1"},
                                    { "data": "CourseEnd", "width": "15%" ,"targets": "2"},
                                    { "data": "CourseStartTime", "width": "15%" ,"targets": "3"},
                                    { "data": "Language", "width": "15%","targets": "4" },
    
                                    { "data": "Vacant", "width": "10%","targets": "5" },
                                    {
                                        "render": function(data, type, row, meta) {
                                            
                                            var a= row.Price.replace(/[USD,]+/g,"");
                                            return '<span style="width:15%; , "targets": "6">USD '+ parseFloat(a).toFixed(2) +'</span>' ;
                                        }
                                    },
                                    { "data": "Sessi

    In the line "var a= row.Price.replace(/[USD,]+/g,"");"

    In the above I hardcoded the currency because it was known, but many times it is unknown and can be any currency, how can I replace them if they are unknow.?

    Tuesday, October 24, 2017 9:01 AM

All replies

  • User-1838255255 posted

    Hi khan_1,

    According to your description, as far as I know, you could use ^\D+ to replace all non number data, then handle number. For more details, please check the following sample:

    Sample Code:

    <head runat="server">
        <title></title>
        <script>
            var allamounts = ["KS32.364", "SH56.65934"];
            for (var i = 0; i < allamounts.length; i++) {
                show(allamounts[i]);
            }
            function show(data) {
                debugger;
                var result = data.replace(/^\D+/g, '');
                var num = parseFloat(result).toFixed(2);
                document.write(num + "</br>");
            }
        </script>
    </head>

    Best Regards,

    Eric Du

    Tuesday, October 24, 2017 12:39 PM