Обработка вида Unix символа подчеркивания

Вот быстрый способ использования регулярных выражений и замены.

function formatCurrency( number, dp, ts ) {
  var num = parseFloat( number ); //convert to float
  var pw; //for IE
  dp = parseInt( dp, 10 ); //decimal point
  dp = isNaN( dp ) ? 2 : dp; //default 2 decimal point
  ts = ts || ','; //thousands separator

  return num != number ? 
    false : //return false for NaN
    ( ( 0.9 ).toFixed( 0 ) == '1' ? //for cater IE toFixed bug
        num.toFixed( dp ) : //format to fix n decimal point with round up
        ( Math.round( num * ( pw = Math.pow( 10, dp ) || 1 ) ) / pw ).toFixed( dp ) //for fix ie toFixed bug on round up value like 0.9 in toFixed
    ).replace( /^(-?\d{1,3})((\d{3})*)(\.\d+)?$/, function( all, first, subsequence, dmp, dec ) { //separate string into different parts
      return ( first || '' ) + subsequence.replace( /(\d{3})/g, ts + '$1' ) + ( dec || '' ); //add thousands seperator and re-join all parts
    } );
}
21
задан Joshua 22 February 2019 в 14:57
поделиться

3 ответа

You can set LC_COLLATE to traditional sort order just for your command:

env LC_COLLATE=C sort tmp

This won't change the current environment just the one in which the sort command executes. You should have the same behaviour with this.

27
ответ дан 29 November 2019 в 21:12
поделиться

sort order depends on the current value of the environment variable LC_COLLATE. Check your local documentation for 'locale', 'setlocale', etc. Set LC_COLLATE to 'POSIX' on both machines, and the results should match.

4
ответ дан 29 November 2019 в 21:12
поделиться

Разница из-за вашего локаль . Используйте команду locale , чтобы проверить текущие настройки.

Существует несколько различных категорий языковых стандартов, таких как LC_COLLATE , LC_TIME и LC_MESSAGES . Вы можете изменить их все, установив переменную среды LC_ALL или LANG , или только порядок сортировки (сортировки), установив переменную среды LC_COLLATE . Локаль C или POSIX - это базовая локаль, определенная стандартом; другие включают en_US (американский английский), fr_FR (французский) и т. д.

0
ответ дан 29 November 2019 в 21:12
поделиться
Другие вопросы по тегам:

Похожие вопросы: