Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0231cee

Browse files
Dan pricing number format (#1630)
1 parenta13b4ad commit0231cee

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

‎pgml-dashboard/src/components/inputs/range_group_pricing_calc/range_group_pricing_calc_controller.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import{Controller}from"@hotwired/stimulus";
2+
import{
3+
numberToCompact,
4+
compactToNumber,
5+
}from"../../../../static/js/utilities/compact_number";
26

37
exportdefaultclassextendsController{
48
statictargets=["textInput","range"];
@@ -18,7 +22,7 @@ export default class extends Controller {
1822
updateText(e){
1923
if(e.detail>=this.minValue&&e.detail<=this.maxValue){
2024
this.removeErrorState();
21-
this.textInputTarget.value=e.detail;
25+
this.textInputTarget.value=numberToCompact(e.detail);
2226
this.updateDatasetValue();
2327
this.inputUpdated();
2428
}else{
@@ -27,20 +31,22 @@ export default class extends Controller {
2731
}
2832

2933
textUpdated(){
30-
letvalue=Number(this.textInputTarget.value);
34+
letvalue=compactToNumber(this.textInputTarget.value);
35+
3136
if(!value){
32-
value=this.minValue;
33-
this.textInputTarget.value=value;
37+
this.textInputTarget.value=numberToCompact(this.minValue);
3438
}
3539

3640
if(value>this.maxValue||value<this.minValue){
3741
this.applyErrorState();
3842
value=value>this.maxValue ?this.maxValue :this.minValue;
3943
value=value<this.minValue ?this.minValue :value;
44+
this.textInputTarget.value=numberToCompact(value);
4045
this.dispatchToRange(value);
4146
}else{
4247
this.removeErrorState();
4348
this.dispatchToRange(value);
49+
this.textInputTarget.value=numberToCompact(value);
4450
this.updateDatasetValue();
4551
this.inputUpdated();
4652
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
exportconstnumberToCompact=(num)=>{
3+
if(num>=1e12){
4+
return(num/1e12).toFixed(1)+'T';// Trillion
5+
}elseif(num>=1e9){
6+
return(num/1e9).toFixed(1)+'B';// Billion
7+
}elseif(num>=1e6){
8+
return(num/1e6).toFixed(1)+'M';// Million
9+
}elseif(num>=1e3){
10+
return(num/1e3).toFixed(1)+'K';// Thousand
11+
}else{
12+
returnnum.toString();// Less than a thousand
13+
}
14+
};
15+
16+
exportconstcompactToNumber=(compact)=>{
17+
constsuffixes={'K':1e3,'M':1e6,'B':1e9,'T':1e12};
18+
constregex=/^(\d+(\.\d+)?)([KMBT])$/;
19+
20+
constmatch=compact.match(regex);
21+
if(match){
22+
constnumber=parseFloat(match[1]);
23+
constsuffix=match[3].toUpperCase();
24+
returnnumber*suffixes[suffix];
25+
}else{
26+
returnparseFloat(compact);// For numbers without suffixes
27+
}
28+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp