作者: admin

  • js金钱格式

    兼容IE8

    效果就是输入数字时,自动将数字格式化为国际金钱的格式,例如:

    3234.99 转 3,234.99

    不仅如此还支持双向数据绑定的功能。

     

    参考英文文档:

     

    accounting.js

    accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). It’s lightweight, fully localisable and has zero dependencies.

    Library Methods

    formatMoney() – format any number into currency

    The most basic function of this library is money-formatting numbers, with currency symbol, precision (places), and thousand/decimal separators:

    // Default usage:
    
    accounting.formatMoney(12345678);// $12,345,678.00// European formatting (custom symbol and separators), could also use options object as second param:
    
    accounting.formatMoney(4999.99,"€",2,".",",");// €4.999,99// Negative values are formatted nicely, too:
    
    accounting.formatMoney(-500000,"£ ",0);// £ -500,000// Simple `format` string allows control of symbol position [%v = value, %s = symbol]:
    
    accounting.formatMoney(5318008,{ symbol:"GBP",  format:"%v %s"});// 5,318,008.00 GBP

    formatColumn() – format a list of values for column-display

    This table demonstrates how accounting.js can take a list of numbers and money-format them with padding to line up currency symbols and decimal places (NB: white-space:pre is needed for the browser to render the padded spaces):

    Original Number: With accounting.js: Different settings: European format: Symbol after value:
    123.5 $ 123.50 HK$ 124 € 123,50 123.50 GBP
    3456.615 $ 3,456.62 HK$ 3,457 € 3.456,62 3,456.62 GBP
    777888.99 $ 777,888.99 HK$ 777,889 € 777.888,99 777,888.99 GBP
    -5432 $ -5,432.00 HK$ (5,432) € -5.432,00 -5,432.00 GBP
    -1234567 $ -1,234,567.00 HK$ (1,234,567) € -1.234.567,00 -1,234,567.00 GBP
    0 $ 0.00 HK$ — € 0,00 0.00 GBP
    // Format list of numbers for display:
    
    accounting.formatColumn([123.5,3456.49,777888.99,12345678,-5432],"$ ");

    formatNumber() – format a number with custom precision and localisation

    The base function of the library, which takes any number or array of numbers, runs accounting.unformat() to remove any formatting, and returns the number(s) formatted with separated thousands and custom precision:

    accounting.formatNumber(5318008);// 5,318,008
    
    accounting.formatNumber(9876543.21,3," ");// 9 876 543.210

    toFixed() – better rounding for floating point numbers

    Implementation of toFixed() that treats floats more like decimal values than binary, fixing inconsistent precision rounding in JavaScript (where some .05 values round up, while others round down):

    (0.615).toFixed(2);// "0.61"
    
    accounting.toFixed(0.615,2);// "0.62"

    unformat() – get a value from any formatted number/currency string

    Takes any number and removes all currency formatting:

    accounting.unformat("£ 12,345,678.90 GBP");// 12345678.9

    Demo / Try it out

    Money formatting:

    Enter any number into the box and choose currency. Uses accounting.formatMoney():

     

    Result: $ 0.00

    Column formatting:

    Edit the values in the table to see how formatColumn() keeps them aligned:

    $ 1,000,000.00 GBP 1,000,000
    $ 3,234.99 GBP 3,235
    $ 0.00 GBP —

    Instructions / How to use

    1. Download the script and put it somewhere, then do this:

    <scriptsrc="path/to/accounting.js"></script><scripttype="text/javascript">// You can do this now:
    
    	accounting.formatMoney(5318008);</script>

    2. Check out the documentation and source-code for full method/parameter info if you get stuck.

    Documentation

    Information on the parameters of each method. See library methods above for more examples. Optional parameters are in [italics], with the default value indicated.

    accounting.settings

    // Settings object that controls default parameters for library methods:
    
    accounting.settings ={
    
    	currency:{
    
    		symbol :"$",// default currency symbol is '$'
    
    		format:"%s%v",// controls output: %s = symbol, %v = value/number (can be object: see below)
    
    		decimal :".",// decimal point separator
    
    		thousand:",",// thousands separator
    
    		precision :2// decimal places},
    
    	number:{
    
    		precision :0,// default precision on numbers is 0
    
    		thousand:",",
    
    		decimal :"."}}// These can be changed externally to edit the library's defaults:
    
    accounting.settings.currency.format ="%s %v";// Format can be an object, with `pos`, `neg` and `zero`:
    
    accounting.settings.currency.format ={
    
    	pos :"%s %v",// for positive values, eg. "$ 1.00" (required)
    
    	neg :"%s (%v)",// for negative values, eg. "$ (1.00)" [optional]
    
    	zero:"%s  -- "// for zero values, eg. "$  --" [optional]};// Example using underscore.js - extend default settings (also works with $.extend in jQuery):
    
    accounting.settings.number = _.defaults({
    
    	precision:2,
    
    	thousand:" "}, accounting.settings.number);

    accounting.formatMoney()

    // Standard usage and parameters (returns string):
    
    accounting.formatMoney(number,[symbol ="$"],[precision =2],[thousand =","],[decimal ="."],[format ="%s%v"])// Second parameter can be an object:
    
    accounting.formatMoney(number,[options])// Available fields in options object, matching `settings.currency`:var options ={
    
    	symbol :"$",
    
    	decimal :".",
    
    	thousand:",",
    
    	precision :2,
    
    	format:"%s%v"};// Example usage:
    
    accounting.formatMoney(12345678);// $12,345,678.00
    
    accounting.formatMoney(4999.99,"€",2,".",",");// €4.999,99
    
    accounting.formatMoney(-500000,"£ ",0);// £ -500,000// Example usage with options object:
    
    accounting.formatMoney(5318008,{
    
    	symbol:"GBP",
    
    	precision:0,
    
    	thousand:"·",
    
    	format:{
    
    		pos :"%s %v",
    
    		neg :"%s (%v)",
    
    		zero:"%s  --"}});// Will recursively format an array of values:
    
    accounting.formatMoney([123,456,[78,9]],"$",0);// ["$123", "$456", ["$78", "$9"]]

    accounting.formatColumn()

    // Standard usage and parameters (returns array):
    
    accounting.formatColumn(list,[symbol ="$"],[precision =2],[thousand =","],[decimal ="."],[format ="%s%v"])// Second parameter can be an object (see formatNumber for available options):
    
    accounting.formatColumn(list,[options])// Example usage (NB. use a space after the symbol to add arbitrary padding to all values):var list =[123,12345];
    
    accounting.formatColumn(list,"$ ",0);// ["$    123", "$ 12,345"]// List of numbers can be a multi-dimensional array (formatColumn is applied recursively):var list =[[1,100],[900,9]];
    
    accounting.formatColumn(list);// [["$  1.00", "$100.00"], ["$900.00", "$  9.00"]]

    accounting.formatNumber()

    // Standard usage and parameters (returns string):
    
    accounting.formatNumber(number,[precision =0],[thousand =","],[decimal ="."])// Second parameter can also be an object matching `settings.number`:
    
    accounting.formatNumber(number,[object])// Example usage:
    
    accounting.formatNumber(9876543);// 9,876,543
    
    accounting.formatNumber(4999.99,2,".",",");// 4.999,99// Example usage with options object:
    
    accounting.formatNumber(5318008,{
    
    	precision :3,
    
    	thousand :" "});// Will recursively format an array of values:
    
    accounting.formatNumber([123456,[7890,123]]);// ["123,456", ["7,890", "123"]]

    accounting.toFixed()

    // Standard usage and parameters (returns string):
    
    accounting.toFixed(number,[precision =0]);// Example usage:
    
    accounting.toFixed(0.615,2);// "0.62"// Compare to regular JavaScript `Number.toFixed()` method:(0.615).toFixed(2);// "0.61"

    accounting.unformat()

    // Standard usage and parameters (returns number):
    
    accounting.unformat(string,[decimal]);// Example usage:
    
    accounting.unformat("GBP £ 12,345,678.90");// 12345678.9// If a non-standard decimal separator was used (eg. a comma) unformat() will need it in order to work out// which part of the number is a decimal/float:
    
    accounting.unformat("€ 1.000.000,00",",");// 1000000

    Roadmap

    See the Github Issues page for up-to-date progress.

    Next Version:

    • Add more fine-grained control of formatting, with negatives and zero-values
    • Implement map() and type-checking helper methods to clean up API methods
    • Find performance bottlenecks and work on speed optimisations
    • Write more tests, docs and examples, add FAQ
    • Implement feedback

    Later:

    • Add padding parameter to override amount of space between currency symbol and value.
    • Add digit-grouping control, to allow eg. “$10,0000”
    • Add choice of rounding method for precision (up, down or nearest-neighbour).
    • Add several other general and excel-style money formatting methods.
    • Create NPM package, if there’s demand for it.
    • Create wrapper for jQuery as a separate plugin (not in core) to allow eg.$('td.accounting').formatMoney()

     http://www.jq22.com/demo/accounting.js-master/

    accounting

  • ubuntu安装配置phpmyadmin

    手动安装顺序:
    1. 安装Apache 参考:《ubuntu安装配置apache
    2. 安装MySQL              《ubuntu安装mysql
    3. 安装PHP                   《ubuntu安装php 7.0
    4.安装phpmyadmin    《ubuntu安装配置phpmyadmin
    5. 配置Apache、PHP
    是为了造成一些不必要的麻烦

    要安装phpmyadmin就必须安装mysql

     

    安装mysql (如果之前安装了在执行一次更新也无妨)

    sudo apt-get install mysql-server
    sudo apt-get install mysql-client //之前我就是因为忘记装了这个,才导致php无法读取mysql数据
    安装时输出root用户的密码

     

    安装phpmyadmin

    sudo apt-get install phpmyadmin
    sudo apt-get install php-mbstring
    sudo apt-get install php-gettext

     

    建立/var/www/html 下的软连接(把share目录下的phpmyadmin快捷键创建到html中)

    sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

     

    重启apache

    sudo /etc/init.d/apache2 restart

     

    登录:

    http://ip/phpmyadmin/

    输入帐号密码

     

    如果要使用phpmyadmin导入数据库可能需要修改限制大小

    /etc/php/7.0/apache2/php.ini

    修改以下3个值,改大点。

    upload_max_filesize
    memory_limit
    post_max_size

    http://blog.csdn.net/l6807718/article/details/51374915

  • 解决:Ubuntu运行Chrome出现“Google Chrome can not be run as root”

    打开

    sudo gedit /opt/google/chrome/google-chrome

     

    到最后一行将

    exec -a "$0" "$HERE/chrome" "$@"

    改成

    exec -a "$0" "$HERE/chrome" "$@" --user-data-dir $HOME
  • ubuntu远程连接ubuntu

    在这之前最好先安装SSH,参考教程《在windows中远程登录ubuntu

    1,首先找到这两个ubuntu自带的软件

    des1

     

    2,设置桌面共享

    des2

     

    3,开始连接

    des3

     

    4, (有RDP就选择,如果没有就选择SSH)

    des4

    http://jingyan.baidu.com/article/59703552f9758e8fc00740ce.html

     

     

  • 在windows中远程登录ubuntu—xrdp

    教程1:

    远程登录ubuntu以及其他版本的linux就必须要安装ssh。

    如何查看自己是否已经安装了ssh,直接输入:

    sudo apt-get install ssh

    如果已经安装就会提示,已经是最新版本无需在安装,如果没有安装就提示安装。

    安装完成后输入:

    ps -e|grep sshd

    如果看见有类似:

    4639 ? 00:00:00 sshd

    说明已经安装了,现在启动ssh输入:

    /etc/init.d/ssh start

    ——————————————————————————-

    以上教程是针对没有安装SSH写的,现在介绍在windows下使用 putty来远程操作ubuntu。

    下载 putty直接双击启动,看见如图:

    putty1

    输入远程主机IP或域名,设定端口为22号端口,登录协议选择SSH,点open登录

     

     

    putty2

    第一次登录会出现指纹认证信息,这里点YES即可

     

     

    putty3

     

    之后输入帐号密码,剩下的就可以在DOM界面操作远程ubuntu了

    —————————————————————————————-

    教程2:

    本人测试用win7自带的远程桌面连接工具连接远程的ubuntu成功。

    1,首先还是确保安装了ssh。

    2,设置下装面共享,如图:

    putty4

     

    3,接下来照着以下顺序安装软件:

    sudo apt-get install xrdp
    sudo apt-get install vnc4server
    sudo apt-get install xubuntu-desktop
    echo "xfce4-session" >~/.xsession
    sudo service xrdp restart

     

    4,接着获取到远程ubuntu的IP地址,在win7下打开远程桌面软件“win+R”输入mstsc。之后输入IP和帐号密码,登录成功后还会在提示你输入一次密码,这时候就能看到一个登录界面了。

     http://jingyan.baidu.com/article/8ebacdf0cdc64949f75cd555.html

    如果帐号密码输入正确进入的时候是黑屏,鼠标是交叉x的话,那么就执行以下步骤:

    sudo apt-get install xubuntu-desktop
    echo xfce4-session >~/.xsession
    sudo gedit /etc/xrdp/startwm.sh
    在./etc/X11/Xsession前插入
    xfce4-session
    后保存,如图:
    putty5
    
    
    cd /etc/init.d/
    ./xrdp restart //重启xrdp