number-formatting

How can I format a decimal in xquery?

二次信任 提交于 2019-12-05 06:11:35
I'm trying to format decimals in XQuery. The decimals are currency, so the format should be ,###.## . For example: 5573652.23 should be 5,573,652.23 and 352769 should be 352,769 (or 352,769.00 if it's easier/cleaner) Right now I'm using this function from http://www.xqueryhacker.com/2009/09/format-number-in-xquery/ , but I can't use decimals with it: declare function local:format-int($i as xs:int) as xs:string { let $input := if ($i lt 0) then fn:substring(fn:string($i), 2) else fn:string($i) let $rev := fn:reverse(fn:string-to-codepoints(fn:string($input))) let $comma := fn:string-to

How can I change the TEdit default error message (NumbersOnly mode)?

≯℡__Kan透↙ 提交于 2019-12-05 02:03:00
How can I change the TEdit's default error message when I use it in NumbersOnly mode. I mean this error: Unacceptable character You can only type a number here Is it possible to change this message ? I don't know a direct way to change the value of that message (which is handled by Windows) but you can show your own message and then avoid to show the original windows hint ballon, using the Abort procedure in the OnKeyPress Event. Check this sample procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (CharInSet(Key,['0'..'9',#8,#9])) then begin ShowHintMessage('Only

Dart - NumberFormat

江枫思渺然 提交于 2019-12-05 01:19:15
Is there a way with NumberFormat to display : '15' if double value is 15.00 '15.50' if double value is 15.50 Thanks for your help. Actually, I think it's easier to go with truncateToDouble() and toStringAsFixed() and not use NumberFormat at all: n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2); So for example: main() { double n1 = 15.00; double n2 = 15.50; print(format(n1)); print(format(n2)); } String format(double n) { return n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2); } Prints to console: 15 15.50 Edit: The solution posted by Martin seens to be a better one I don't think this

how can I remove zeros from exponent notation

喜欢而已 提交于 2019-12-05 00:57:40
I'm using exponential formatting to format a decimal number in C#. For example if the number is 0.0001234567 Formatting with (0.0000123456).ToString("E4"); Shows 1.2345E-004 How can I remove leading zero from exponent so it read as below? 1.2345E-4 Assuming you need to always show 4 digits after decimal point, try "0.0000E+0" so it will show (0.0000123456).ToString("0.0000E+0"); //1.2345E-5 (0.0000120000).ToString("0.#E+0"); //1.2000E-5 if you don't need to show 4 digits after decimal points use "0.#E+0" so it will show (0.0000123456).ToString("0.#E+0"); //1.2E-5 (0.0000120000).ToString("0.#E

Add commas as thousands separator and floating point dot in php

空扰寡人 提交于 2019-12-04 23:14:16
I have this $example = "1234567" $subtotal = number_format($example, 2, '.', ''); the return of $subtotal is "1234567.00" how to modify the definition of $subtotal, make it like this "1,234,567.00" Below will output 1,234,567.00 $example = "1234567"; $subtotal = number_format($example, 2, '.', ','); echo $subtotal; Syntax string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' ) But I advise you to use money_format which will formats a number as a currency string Nathan Srivi You have many options, but money_format can do the trick for

How can I change DecimalFormat behavior based on input length?

喜欢而已 提交于 2019-12-04 20:31:42
问题 I am using the following DecimalFormat pattern: // Use ThreadLocal to ensure thread safety. private static final ThreadLocal <NumberFormat> numberFormat = new ThreadLocal <NumberFormat>() { @Override protected NumberFormat initialValue() { return new DecimalFormat("#,##0.00"); } }; This performs the following conversions: 1 -> 1.00 1.1 -> 1.10 1.12 -> 1.12 I now have an additional requirement. 1.123 -> 1.123 1.1234 -> 1.123 That means that when there are fewer than two decimal places, I will

How do I format my percent variable to 2 decimal places?

亡梦爱人 提交于 2019-12-04 18:00:21
问题 This program is basically working with text files, reading the data & performing functions: while(s.hasNext()){ name= s.next(); mark= s.nextDouble(); double percent= (mark / tm )*100 ; System.out.println("Student Name : " +name ); System.out.println("Percentage In Exam: " +percent+"%"); System.out.println(" "); } I would like to format the percent value to 2 decimal places but since it's inside a while loop I cannot use the printf. 回答1: Elliot's answer is of course correct, but for

How to make single digit number a two digit number in ruby?

老子叫甜甜 提交于 2019-12-04 17:50:20
问题 Time.new.month returns a single digit representation of any month prior to October (e.g. June is 6 ), but I want a 2-digit format (i.e. instead of 6 I want 06 ). I wrote the following solution, and I am asking to see some other/better solutions. s = 6.to_s; s[1]=s[0]; s[0] = '0'; s #=> '06' 回答1: For your need I think the best is still Time.strftime("%m") as mentioned but for general use case the method I use is str = format('%02d', 4) puts str depending on the context I also use this one

PHP remove first zeros

房东的猫 提交于 2019-12-04 16:05:44
问题 Want to remove all 0 placed at the beginning of some variable. Some options: if $var = 0002 , we should strip first 000 ( $var = 2 ) if var = 0203410 we should remove first 0 ( $var = 203410 ) if var = 20000 - do nothing ( $var = 20000 ) What is the solution? 回答1: cast it to integer $var = (int)$var; 回答2: Maybe ltrim ? $var = ltrim($var, '0'); 回答3: $var = ltrim($var, '0'); This only works on strings, numbers starting with a 0 will be interpreted as octal numbers, multiple zero's are ignored.

How do you use number_to_phone in Rails 3?

孤者浪人 提交于 2019-12-04 15:18:55
I am storing phone number in database as "1234567890". How do can you use number_to_phone to display the number nicely in a form as "(123) 456-7890"? I tried the following but it showed just the numbers. <%= f.text_field number_to_phone(:phone_number) %> Thanks. you can create a simple helper like this in your application helper def format_phone(phone, mobile=false) return phone if format.blank? groupings = format.scan(/d+/).map { |g| g.length } groupings = [3, 3, 4] unless groupings.length == 3 ActionController::Base.helpers.number_to_phone( phone, :area_code => format.index('(') ? true :