Skip to content

Commit 301f0d5

Browse files
committed
feat: add toFloat and fromFloat to BZZ and DAI classes
1 parent 471d5ce commit 301f0d5

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
"dependencies": {
6464
"axios": "^1.15.1",
65-
"cafe-utility": "^33.6.1",
65+
"cafe-utility": "^33.9.0",
6666
"debug": "^4.4.1",
6767
"isomorphic-ws": "^4.0.1",
6868
"semver": "^7.3.5",

src/utils/tokens.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class BZZ {
1818
return new BZZ(new FixedPointNumber(plur, BZZ.DIGITS))
1919
}
2020

21+
public static fromFloat(float: number) {
22+
return new BZZ(FixedPointNumber.fromFloat(float, BZZ.DIGITS))
23+
}
24+
2125
public toPLURString() {
2226
return this.state.toString()
2327
}
@@ -30,6 +34,10 @@ export class BZZ {
3034
return this.state.toDecimalString()
3135
}
3236

37+
public toFloat() {
38+
return this.state.toFloat()
39+
}
40+
3341
public toSignificantDigits(digits: number) {
3442
return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1)
3543
}
@@ -108,6 +116,10 @@ export class DAI {
108116
return new DAI(new FixedPointNumber(wei, DAI.DIGITS))
109117
}
110118

119+
public static fromFloat(float: number) {
120+
return new DAI(FixedPointNumber.fromFloat(float, DAI.DIGITS))
121+
}
122+
111123
public toWeiString() {
112124
return this.state.toString()
113125
}
@@ -124,6 +136,10 @@ export class DAI {
124136
return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1)
125137
}
126138

139+
public toFloat() {
140+
return this.state.toFloat()
141+
}
142+
127143
/**
128144
* Does not mutate the current DAI instance.
129145
*

0 commit comments

Comments
 (0)