mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Update isFloat util to handle strings
This commit is contained in:
parent
1968812814
commit
236f8277f7
2 changed files with 11 additions and 5 deletions
|
@ -306,10 +306,7 @@ class Rendition {
|
||||||
this.displaying = displaying;
|
this.displaying = displaying;
|
||||||
|
|
||||||
// Check if this is a book percentage
|
// Check if this is a book percentage
|
||||||
if (this.book.locations.length() &&
|
if (this.book.locations.length() && isFloat(target)) {
|
||||||
(isFloat(target) ||
|
|
||||||
(target === "1.0")) // Handle 1.0
|
|
||||||
) {
|
|
||||||
target = this.book.locations.cfiFromPercentage(parseFloat(target));
|
target = this.book.locations.cfiFromPercentage(parseFloat(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,16 @@ export function isNumber(n) {
|
||||||
*/
|
*/
|
||||||
export function isFloat(n) {
|
export function isFloat(n) {
|
||||||
let f = parseFloat(n);
|
let f = parseFloat(n);
|
||||||
return f === n && isNumber(n) && (Math.floor(f) !== n);
|
|
||||||
|
if (isNumber(n) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof n === "string" && n.indexOf(".") > -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.floor(f) !== f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue