i have an interactive report in my apex page with numbers (money) in it, the default money format is U.S which is like this :
###,###,###,###.##
what i need is this :
### ### ### ###,##
is there a way to do so in HTML or in CSS or JAVASCRIPT
The display format in an apex report is determined by 2 parameters:
Appearance > Format Mask of the column in your interactive report
Decimal and Group separator set in the database session.
Decimal and group separator
In oracle this is determined at session level. You want , as decimal and space as group separator. To change this for your database session run the following statement.
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ', ';
To change this for your entire application, set the following in Shared Components > Security > Database Session > Initialization PL/SQL Code
EXECUTE IMMEDIATE q'!ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ', '!';
To just set this for the page you have your report on you can either use an application process (with condition Current Page is contained within expression) = "your page" or a before header process to execute the EXECUTE IMMEDIATE statement above
Format Mask
The Number Format Models documentation might give you some clues here: 9is a NUMBER, D is the decimal separator, G is the group separator. So you're looking for 999G999G999G999D99
SELECT TO_CHAR(9866166747393/100,'999G999G999G999D99') from dual;
98 661 667 473,93
Set this as Appearance > Format Mask of the column in your interactive report.
How about
Intl.NumberFormat
or
toLocaleString
const number = 10000.50
console.log(new Intl.NumberFormat('fr-FR',{minimumFractionDigits:2}).format(number))
console.log(number.toLocaleString('fr-Fr', {
style: 'currency',
currency: 'EUR',
minimumFractionDigits: 2
}));
Related
I'm trying to set the number of decimals at 2 in an input. When I type a comma in it, the value becomes NaN so I would like get my number instead of this.
TS
#ViewChild('number') input;
limitNbOfDecimals() {
var regex =
this.form.number.search(/^(\d+(?:[\.\,]\d{0,2})?)$/) == 0
? true
: false;
if (regex == false) {
// Convert the value to a number
var nb: number = +this.input.nativeElement.value;
//set decimals at 2
this.input.nativeElement.value = nb.toFixed(2);
}
}
HTML
<input class="form-control" type="text" [(ngModel)]="form.number"
#number
name="number"
(input)="limitNbOfDecimals()"
/>
EDIT
I manage to add a comma in the number but if I try to add more than 2 decimals after it removes the numbers after the comma like 1,11 -> 1
This isn't a full answer, in the sense of having a total solution, but hopefully helps you get to one (and it's too long for a comment).
The spec at https://html.spec.whatwg.org/multipage/input.html#number-state-(type=number) states:
This specification does not define what user interface user agents
are to use; user agent vendors are encouraged to consider what would
best serve their users' needs. ..... a user agent designed for the
French market might display the value with apostrophes between
thousands and commas before the decimals, and allow the user to enter
a value in that manner, internally converting it to the submission
format described above.
It would seem that the only sure way - if you don't have control over what browsers your users have - of ensuring they can type numbers in the format they are used to in their local setting is to take input as type text and on each keystroke check that they have typed something valid (as you have defined it) and when they submit it convert to a decimal number.
Searching provides code for doing this, depending on exactly what your requirement is for the number formats though you may be better off coding it from scratch.
To add more than 2 decimal values, you need to tell like .toFixed(4) etc..
Good afternoon folks!
I'm using React NumberFormat for currency formatting, it works well, but I couldn't reproduce with it the behavior I want for my page.
I would like the user to type in the 1010 input, and the input automatically corrects it to $ 10.10.
However, all the methods I found, when the user types 1010, he corrects it for $ 1010.00.
How do I get to this behavior in real time in the input? As soon as the user types, it is already formatting.
Appreciate!
I need a regular expression or code, where:
I type - return code
1010 ===> 10.10
1000 ====> 10.00
1050 =====> 10.50
100050 ====> 1,000.50
You can try making a "format" function like below:
function formatCurrency(currencyString) {
let firstHalf = currencyString.substring(0, currencyString.length - 2);
let secondHalf = currencyString.substring(currencyString.length - 2, currencyString.length);
return parseFloat(`${firstHalf}.${secondHalf}`).toLocaleString('en-EN', {style: 'currency', currency: 'USD'});
}
// example use case:
let cur = formatCurrency('1010'); // returns: '$10.10'
cur = formatCurrency('101010') // returns: '$1,010.10'
This way you are always getting the last two characters on the right side of the decimal, as you're trying to do, and using localization to properly format the number.
Overview:
I'm not a programmer but I managed to get some serious coding into a Gsheets to track my teams project, so we have multiple-variable dropdown menus and integration with google calendar to track projects development and all that.
Why I'm at stackoverflow:
I kind of lack the knowledge to start the code from the scratch, I usually find spare parts of code through forums on the internet and clue them together and it usually works surprisingly well, but this time I couldn't find much informtation.
What I need:
I have 5 cells, and we can put as below,
Date start - Date end - date code* - number** - Priority***
*script to add the date range to gcalendar
** & *** The number is an array that's based on the word written on the priority cell, for example: If priority is written Weekly them
the number colunm will show 7 on the cell to the left and them it
goes. (monthly = 30 and blablabla...)
So I'd like to know if someone could give a hand with a script that would work (at least in my head) as following:
If I set the priority to weekly, it will show 7 on the number colunm and them, every time the "Date end" has passed, it will automatically add 7 days to the "Date start" and "Date end" again.
That way I could keep the projects on a loop where I'll be able to track them constatly.
Thanks in advance for any insights provided,
ps: I've seen some posts about this on sql, but I have no idea also on how to take advantage of the proposals that were presented there.
Edit:
Spreadsheet picture
eDIT2:
Spreadsheet with a increment colunm
Pertinent to the data set and description, you probably do not need any VBA as the increment could be achieved by adding +1 to the reference pointing to previous cell. For example, assuming cell A1 is formatted as Date, enter in cell B1: =A1+1 , then in cell C1: =B1+1 and so on. The result should be as shown below
A B C
9/1/2017 9/2/2017 9/3/2017
It could be further extended with simple logic allowing do display incremented value only if the previous cell is not empty, like : =IF(A1,A1+1,"")
In your case, it could be cell F1 containing =IF(E1,E1+1,"").
FYI, the underlying value of Date is just an Integer value (Time is represented as decimal part), so the arithmetic operations could be applied.
More generic solution would be based on the Excel DATE() Worksheet formula as shown in sample shown below (adding 1 mo. to the date entered in cell A1):
=DATE(YEAR(A1), MONTH(A1)+1, DAY(A1))
In order to implement additional logic, you may consider using Excel Worksheet IF() statement like for example, cell B1 containing:
=A1+IF(C1="week",7,1)
A B C
9/1/2017 9/8/2017 week
so based on the IF() condition it will add either 7 days if C1 contains the word "week" or 1 day otherwise. It could be further extended with nested IF().
Hope this will help.
I have a web application with some calculations in text fields. Application is worked in asp.net using vb. I have JavaScript that need to do some calculations every time onTextChange action.
For example I have to enter a number in this format 123.123 or 123 and at the end I want to calculate all text fields and to do formatting like this 123.123,00 or 123,00
For now I am using:
document.getElementById('<%=FV.FindControl("txtSUM").ClientID%>').value = ("" + sum).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, function ($1) { return $1 + "." });
but this only adding a point on thousand, apart from that I want to add and comma on decimal place.
I followed this guide to export an Excel Spreadsheet as an XML data file and then this guide to display the XML sheet as an HTML table on my website. It worked great. Now I "only" have to small issues remaining that I couldn't get solved.
(1) The output table contains numbers like 1.325667 but also lots of 0s. I would like the zeroes to be displayed as 0.00 and the numbers with many decimals to be displayed as 1.33. Basically, each number should be displayed with two decimals.
(2) The excel sheet contains hyperlinks to other pages on my website that I would like to keep when rendering the XML data file and then the HTML table. So far, that didn't work. Is this possible?
UPDATE I figured this part out. By breaking up the hyperlinks in just their character-strings, then adding new columns for these character strings, and then tweaking the source code to including
document.write("<tr><td><a href='");
document.write(x[i].getElementsByTagName("character-string")0].childNodes[0].nodeValue);
document.write(".php'>");
document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
document.write("</a></td>");
I was able to include hyperlinks.
The Excel-Sheet is formatted with these two aspects already integrated, but the conversion to an XML file seems to be the problem.
Thank you so much for your help (again and again :-))
UPDATE I now also found a way to do the rounding in Excel, but I'm still stuck with integers and numbers with only one decimal. Basically, I now "only" need a way to show every number with two decimal points, applying to integers (e.g. 0 should 0.00) and numbers with one decimal (e.g. 1.5 should be 1.50). JohnnyReeves' answer seems to be on the right track but I couldn't get it to work. Any other ideas?
The Number Object has the method toFixed():
1.325667.toFixed(2) = 1.33.
Running inside the loop of the XML, select the URL and add it to the link:
document.write("< a href=" + x[i].getElementsByTagName(< your URL link>) + ">);
document.write("some text");
document.write("< /a>");
The Number.toFixed method will only work on floating point values (eg: 2.1), but not on integers (eg: 2, or 0). You will need to convert your number type to a string type so you can format it for display and get consistent results regardless of the input. A function like this should do the trick:
function formatNumber(value) {
var parts,
trailingDigits,
formattedRemainder;
// Coerce the supplied value to a String type.
value = String(value);
// Break the supplied number into two parts, before and after the dot
parts = value.split(".");
// If there was no dot, there will only be one "part" and we can just
// add the trailing zeros.
if (parts.length === 1) {
formattedRemainder = "00";
}
else {
trailingDigits = parts[1];
if (trailingDigits.length === 0) {
// A dot, but no digits. (eg: 2. -> 2.00)
formattedRemainder = "00";
}
else if (trailingDigits.length === 1) {
// Add an extra trailing zero (eg: 2.1 -> 2.10)
formattedRemainder = trailingDigits + "0";
}
else {
// Just take the last two trailing digits.
formattedRemainder = trailingDigits.substring(0, 2);
}
}
// Build the final formatted string for display.
return parts[0] + "." + formattedRemainder;
}