number-formatting

Convert string to decimal number with 2 decimal places in Java

試著忘記壹切 提交于 2019-12-07 05:51:46
问题 In Java, I am trying to parse a string of format "###.##" to a float. The string should always have 2 decimal places. Even if the String has value 123.00 , the float should also be 123.00 , not 123.0 . This is what I have so far: System.out.println("string liters of petrol putting in preferences is " + stringLitersOfPetrol); Float litersOfPetrol = Float.parseFloat(stringLitersOfPetrol); DecimalFormat df = new DecimalFormat("0.00"); df.setMaximumFractionDigits(2); litersOfPetrol = Float

Where to format numbers in CodeIgniter?

大憨熊 提交于 2019-12-07 05:09:42
问题 shell i format my numbers 1234.20 => 1'234.20 in model or in view using php and codeigniter? 回答1: It belongs to the view layer. The model only cares about the value, not how you present it to the user. Also, you may need to display it differently, if your site is multilingual. 回答2: In the view, since the transformation is presentational in nature. 回答3: I would format it in the view, because this sperates the visual from the rest. 来源: https://stackoverflow.com/questions/3237195/where-to-format

how to format a number to S9(5)V99 ascii in .net

Deadly 提交于 2019-12-07 04:26:10
问题 I've been searching for s9(5)v99 but got different information and not really clear. Could someone shows how or the formula to convert. thanks 回答1: What you have shown us here is the PICTURE clause portion of a COBOL data declaration. COBOL data declarations are a bit odd and take some getting used to. Here is a link to an introductory tutorial on COBOL data declarations. This should get you started. The PICture clause you have given in your question is defining a numeric item with the

How can I format a decimal in xquery?

陌路散爱 提交于 2019-12-07 03:08:06
问题 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)

how can I remove zeros from exponent notation

為{幸葍}努か 提交于 2019-12-06 19:22:46
问题 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 回答1: 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

Add commas as thousands separator and floating point dot in php

我与影子孤独终老i 提交于 2019-12-06 17:46:46
问题 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" 回答1: 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

Number formatting in Oracle using TO_CHAR

亡梦爱人 提交于 2019-12-06 13:23:27
Proper way to format the numbers in ORACLE stored procedures. I need to display currency fields with 2 decimals. Expected output is as follows: 0 > 0.00 5 > 5.00 1253.6 > 1253.60 1253.689 > 1253.69 Below worked for me: select to_char(9876.23 , 'fm999990.00') from dual; But this has the issue of hard coding a bunch of 9s. If I give a larger number it will be displayed as "##############" Is there any other way I can do this? I need to display currency fields with 2 decimals. Ensure you use the number data-type with scale and precision appropriate to the data rather than using NUMBER without

how to show certain number of decimal digits

自作多情 提交于 2019-12-06 10:17:22
问题 In Matlab, how to control the number of decimal digits for displaying in command window? For example, >> x=0.4654 x = 0.4654 how to display the value of the variable x as 0.5, 0.47, 0.465 respectively in command window? Thanks! 回答1: I don't think there is built in rounding to arbitrary places, but you can achieve the rounded result by doing round(x*10^ number of places )/10^ number of places . This prints out with the trailing zeroes, if you want to get rid of those you have to do a specially

How do you use number_to_phone in Rails 3?

流过昼夜 提交于 2019-12-06 10:03:13
问题 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. 回答1: 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

How to pass a decimal value from JSP to Action with a Localized decimal separator?

女生的网名这么多〃 提交于 2019-12-06 08:14:01
问题 In the JSP: <input type = "number" name = "score" min = "0" max = "100" maxlength = "3" step = "0.01" /> In the Action: @Getter @Setter private Float score; When the value has decimal places (eg. 56,78 ), in the Action I get 5678.0 . This is due to the fact that Struts2 is not aware that in my country , is the decimal separator, not the thousands separator. Is there a way to instruct Struts2 to use the decimal separator of a specific Locale , so that it will be able to convert the floating