1
0
Fork 0
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:
Fred Chasen 2018-06-14 14:11:40 -07:00
parent 1968812814
commit 236f8277f7
2 changed files with 11 additions and 5 deletions

View file

@ -306,10 +306,7 @@ class Rendition {
this.displaying = displaying;
// Check if this is a book percentage
if (this.book.locations.length() &&
(isFloat(target) ||
(target === "1.0")) // Handle 1.0
) {
if (this.book.locations.length() && isFloat(target)) {
target = this.book.locations.cfiFromPercentage(parseFloat(target));
}

View file

@ -69,7 +69,16 @@ export function isNumber(n) {
*/
export function isFloat(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;
}
/**